3 ms·
I mean, reading zeroed out memory is not really incorrect behaviour anyway. If you know that it was zeroed out, then you're really just reading memory that was
by DrJokepu 11y ago
I mean, reading zeroed out memory is not really incorrect behaviour anyway. If you know that it was zeroed out, then you're really just reading memory that was initialised with a specific default value.
That being said, zeroing out everything you allocate will make it difficult for the kernel's paging system to defer allocating you a physical page until you actually need it, so you will need to be a lot more careful with your allocations if your application uses relatively large amounts of memory and you need to work with memory constraints.
- rc4algorithm 11y agoUnless the zeroing is defined by the language, assuming it t is incorrect and shouldn't be done.
- lmm 11y agoCalloc is defined to return memory that's all-bits-zero, which in turn defines the value for many datatypes. The overwhelming majority of C implementations additionally define the values of all-bits-zero floats and pointers. IMO it's reasonable to write programs targeting only such implementations, provided such a dependency is clearly documented (just as e.g. it's reasonable to write C programs targeting only implementations on which floating-point arithmetic is IEEE 754, despite this not being required by the C standard).
- rc4algorithm 11y ago> The overwhelming majority of C implementations additionally define the values of all-bits-zero floats and pointers. So... Clang and GCC? Regardless, you're ignoring the obvious difference: that isn't POSIX- or ISO-defined at all. If you choose to use it, you're using a weird dialect. Might as well just switch to Cyclone.
- lmm 11y ago> that isn't POSIX- or ISO-defined at all. If you choose to use it, you're using a weird dialect. People used C (even on multiple compilers) long before POSIX or ISO. You're putting the standardization cart before the compatibility horse.
- rc4algorithm 11y agoYeah, let's revert to 1988! Great solution! Muchly of advance!