This article link:http://www.cnblogs.com/xxNote/p/4009359.html
Reading today when you see the free function to release the memory of the dynamic application only need to pass the first address of the memory block, it is clear that only the first address is unable to determine how much memory to release, guess should be somewhere to store the size of this memory block, Search on the internet found in the Linux glibc in allocating memory when the memory block in front of the address of 4 bytes out of the size of the memory block, it is assumed that Windows should be the same. Wrote a small program tested under:
#include <stdio.h> #include <stdlib. H>int Main (void) {int *p = (int *) malloc (int); *p = 1;free (p); return 0;}
To run debugging, find the address of this memory block first:
Now look at the memory:
Since the application of 40 bytes of memory block, converted to 16 is 0x00000028, in memory is 28 00 00 00, look at the memory block before the first address of the 16 bytes and the results of the conjecture, then request a 400-byte size of memory block, Convert to 16 is 0x00000190, in memory is 90 01 00 00, and then look at the results of the operation:
is still the same as the inferred results, visible in Windows when we use the free function to release memory, the function will be the memory block of the first address plus 16, from this location can find the size of the memory block.
The free function in the C language determines how much memory space to release