3 ms·
How does one guarantee that allocated memory is real? Can you easily wrap malloc to zero/poke the memory in a way that catches all exceptions and guarantees yay
by aetherspawn 7y ago
How does one guarantee that allocated memory is real? Can you easily wrap malloc to zero/poke the memory in a way that catches all exceptions and guarantees yay or nay ?
- anilakar 7y agoJens Gustedt suggested the following: memset(malloc(size), 0, 1) The program will crash if malloc returns NULL or the memory is not writable.
- hyperman1 7y agoAnd then memory deduplication comes along, finds out a huge number of identical pages (all zero) and decides to deduplicate them. So if you want your memory to stay real, I suppose you'd better fill it with random data or something.
- shereadsthenews 7y agoYou must use mlock call if you want to guarantee that no later action can suffer a major page fault.