3 ms·
No, it doesn't. malloc(0) != malloc(0) because the internal malloc header is different for each allocation. Asking for a malloc of size n, means internally th
by jra_samba 4y ago
No, it doesn't.
malloc(0) != malloc(0) because the internal malloc header is different for each allocation.
Asking for a malloc of size n, means internally the malloc library allocates n + h, where h is the internal malloc header size. So there is always an allocation being done for at least a size of h, just with an internal bookkeeping "size" field set to zero.
and yes, while(1) malloc(0); will eventually run out of memory, counter-intuitively :-).