On Sun, 16 Mar 2003 20:39:45 -0800, Justin Walker <justin@mac.com> wrote:
On Sunday, Mar 16, 2003, at 19:05 US/Pacific, Eric Grant wrote:
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?
None of the above? I'd say it was normal from my experience. Nothing
violates the description you quote above, at any rate. AFAIK, this is
the way most unices act for realloc, and in addition, address space
acquired in the process of malloc()ing space is never returned.
It violates the description because to say that an allocated memory block referenced by ptr has a particular "size" is to say that the logical address space bounded by {ptr, ptr + size} is NOT available for later allocation and, conversely, that logical address space outside those bounds (and also outside all other allocated blocks) IS available for allocation. Surely, you don't mean to say that address space acquired in the process of malloc()ing space is not returned even when it is free()d?
This is really a topic for darwin-developers, not darwin-kernel. The
kernel just provides resources for user-mode operation, and it's
user-mode that dictates policy (at least for this issue).
I've posted my message there. Thanks. 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