Twenty Bytes Costs Thirty-Two
struct point { int x, y; char label[12]; }; /* sizeof == 20 */
struct point **v = malloc(2400000 * sizeof *v);
for (long i = 0; i < 2400000; i++)
v[i] = malloc(sizeof(struct point));
The allocator puts an 8-byte header in front of every chunk, aligns every chunk to 16 bytes, and never hands out a chunk smaller than 32 bytes. Nothing is freed.
Ignoring the v array itself, how many bytes does the heap hold beyond the 48,000,000 bytes the program actually asked for?
Sign in to answer questions and track your progress
Sign In