3 ms·
Is zero better than 0xDEADBEEF or just faster?
by mcculley 4y ago
Is zero better than 0xDEADBEEF or just faster?
- himinlomax 4y agoBetter for memory compression, at least.
- bonzini 4y agoLess likely to cause crashes, probably.
- mcculley 4y agoI have used custom malloc()/free() implementations that do both just so I could find more crashes.
- CJefferson 4y agoOne advantage is that when you allocate the memory back out (either by malloc, or calloc which requires zeroing), you don't have to do anything. It is mentioned that if you write to freed memory, that could lead to later callocs not returning zeroed memory, which shows they are relying on this.
- mcculley 4y agoYeah, if performance is the goal, zero is certainly faster. I have used 0xDEADBEEF to find both free-after-use and use-before-initialize bugs.
- rollulus 4y agoThe advantage of 0xDEADBEEF would be that it reduces the chance of software starting to rely on that value, compared to zero, isn't it?
- frogblast 4y agoMalloc doesn't guarantee zero filling memory, but ObjC and Swift currently need to zero memory immediately after malloc returns it, and they both share C's malloc pool. This makes a lot more performance sense for those languages.
- mzs 4y agoIt's faster: https://community.arm.com/support-forums/f/architectures-and-processors-forum/48350/data-cache-zero-by-virtual-address-dc-zva-instruction https://community.arm.com/support-forums/f/architectures-and...