Why does malloc allocate a different number of bytes than requested?

First, Malloc makes no guarantees that two successive malloc calls return successive pointers.

Second, depending on your specific architecture, different alignment rules apply; sometimes you might ask for a single byte, but the architecture prefers allocations on 8- or 4-byte intervals.

Third, malloc needs some overhead to store how big the allocated block is, etc.

Don’t make assumptions about what malloc is doing past what the documentation says!

Leave a Comment