Based on my experience with some simple test programs (under OS X 10.2.3), and confirmed by my skimming of the sources (Revision 1.1.1.4 of malloc.c), it appears that realloc does not "free" memory (in any meaningful sense) when passed a size smaller than the size originally malloc'd. That is, despite the supposed downsizing of the object, none of the logical address space encompassed by the original object is available to satisfy subsequent allocation requests. For example: p1 = malloc (2 * 1024 * 1024 * 1024); // 2GB p2 = realloc (p1, 1); The result is that half the logical address space has basically disappeared (though it appears to be available to satisfy a request to realloc p2 to a size up to 2GB). To my mind, this result violates the standard (from man realloc):
The realloc() function changes the size of the previously allocated mem-
ory referenced by ptr to size bytes.
Moreover, it is difficult to see how this result is otherwise a "feature." Good? Bad? Ugly? Cheers, Eric Grant _______________________________________________ darwin-kernel mailing list | darwin-kernel@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel Do not post admin requests to the list. They will be ignored.
participants (1)
-
Eric Grant