#47790 - Mucca - Wed Jul 13, 2005 4:31 pm
Hello
we're currently in the process of overloading new and delete, using malloc and free, but some of the behaviour of malloc is confusing us, and I was wondering if anyone has some links to proper documentation (gcc 2.9.5, been looking, me no successful) as to what exactly malloc does. For instance, malloc clearly writes the size (plus 5 or 9) allocated in the four bytes preceeding the space allocated, however the value written there is not exactly the size of the object allocated - more specifically it seems to always be either 5 or 9 larger than the size allocated. Whether it is 5 or 9 is to do with whether malloc allocates an extra four bytes after the space requested. Perhaps there's a compiler flag to prohibit the allocation of these four extra bytes (It could waste a lot of memory when you've got up to 3000 dynamically allocated objects). Finally, what malloc writes directly after the allocated space (including the 4-byte extra piece) is some kind of marker for malloc. Anyone know the format of this marker? This isnt especially important for us, but it interests me nonetheless.
Oh, and Im not really looking for an answer along the lines of "Don't dynamically allocate memory of gba, its teh baddd!". Just looking for documentation, or even source code of malloc if such a thing is available.
Please
.
.
.
Pretty please
.
.
.
with sugar on top
we're currently in the process of overloading new and delete, using malloc and free, but some of the behaviour of malloc is confusing us, and I was wondering if anyone has some links to proper documentation (gcc 2.9.5, been looking, me no successful) as to what exactly malloc does. For instance, malloc clearly writes the size (plus 5 or 9) allocated in the four bytes preceeding the space allocated, however the value written there is not exactly the size of the object allocated - more specifically it seems to always be either 5 or 9 larger than the size allocated. Whether it is 5 or 9 is to do with whether malloc allocates an extra four bytes after the space requested. Perhaps there's a compiler flag to prohibit the allocation of these four extra bytes (It could waste a lot of memory when you've got up to 3000 dynamically allocated objects). Finally, what malloc writes directly after the allocated space (including the 4-byte extra piece) is some kind of marker for malloc. Anyone know the format of this marker? This isnt especially important for us, but it interests me nonetheless.
Oh, and Im not really looking for an answer along the lines of "Don't dynamically allocate memory of gba, its teh baddd!". Just looking for documentation, or even source code of malloc if such a thing is available.
Please
.
.
.
Pretty please
.
.
.
with sugar on top