Re: confusion about memory fragmentation, vm, and blocks
Re: confusion about memory fragmentation, vm, and blocks
- Subject: Re: confusion about memory fragmentation, vm, and blocks
- From: Mario Emmenlauer <email@hidden>
- Date: Thu, 05 Mar 2009 11:52:29 +0100
Hi Shawn,
Shawn Erickson wrote:
On Tue, Mar 3, 2009 at 7:57 AM, Mario Emmenlauer <email@hidden> wrote:
I have a problem understanding memory allocation, blocks and fragmentation.
The amount of memory your application can address at a given time is
limited first by the size of the virtual memory space, minus
reserved/invalid/guard pages, minus pages mapped for shared libraries,
minus pages mapped for use by the OS, etc., minus allocations made by
your code. All of these allocations carve out ranges in your virtual
address space with the unused ranges between them representing
"available" memory to your application.
Can I read up details about that pre-allocated space? Is there a good
tutorial or technote?
I understand it is quite a lot VM that my application consumes upon startup,
about 1GB. It seems a fair amount given that I do 3D rendering and whatnot,
but I would still be curious to reduce it. (I've asked about that in
a separate thread (Why is virtual memory so high? (crash)) a while ago,
but have not yet found a definitive conclusion.
When you allocate (malloc, etc.) a buffer you get back a pointer to a
contiguous virtual memory range (how the API is defined). If you
attempt to allocate a buffer larger then any of the available
contiguous virtual memory ranges it will fail... despite possibly
having smaller contiguous ranges available that, if contiguous, would
have allow the allocation to succeed.
(note I side stepped "pools" of virtual memory pages that malloc
maintains for small, tiny, etc. allocations to minimize fragmentation
and speed re/allocations)
That answers the question perfectly, thanks!
You could consider using a memory mapped file and slide around a
"window" of contiguous mappings over that file. This would limit/bound
how much virtual memory you use at a given time while giving you
access to an arbitrarily large buffer. ...of course it would be far
I haven't done anything like it before, but it sounds very useful -
you would not by any chance know a good book or tutorial on the subject?
easier to switch your application to use a 64b virtual address space.
We have done that just now, ported our code to x86_64. The topic remains
merely because I assume we could improve our memory management.
Best regards,
Mario
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden