Re: Is there a 1GB memory ceiling for vm_allocate?
Re: Is there a 1GB memory ceiling for vm_allocate?
- Subject: Re: Is there a 1GB memory ceiling for vm_allocate?
- From: "Shawn Erickson" <email@hidden>
- Date: Tue, 23 Jan 2007 14:32:23 -0800
On 1/23/07, John Bullitt <email@hidden> wrote:
Hi, folks.
I'm trying to push_back() a bunch of elements into a vector. When
push-back() tries to allocate more than 1GB, it fails.
For example, the following little program will push_back() until it
runs out of memory:
#include <vector>
int main (int argc, char * const argv[]) {
std::vector<char> z;
unsigned long int n;
for (n=0;;n++) {
z.push_back(0);
}
}
I get an error like this: "malloc: *** vm_allocate(size=1073741824)
failed (error code=3)" .
Why is it running out of memory so soon? My G5 has 5 GB of RAM and
175GB free disk space. I'm baffled.
Is there maybe an XCode setting that I missed that can increase VM size?
The VM size isn't the issue really the issue... 32b tasks have a 4 GiB
address space.
The issue you are hitting is the largest contiguous (in terms of
virtual address) allocation that is possible from your virtual space.
In your example the vector is resizing itself when you push_back more
elements then it has space for. In effect the prior vector store
allocation has been carved out a contiguous block of virtual addresses
(as have any other allocations in your application not yet
deallocated) and the new allocation request cannot find a large enough
contiguous range of addresses to satisfy that request.
On Mac OS X around 3 GiB to 3.5 GiB of the 4 GiB virtual address space
is available to your application with the rest taken by mappings of
shared libraries that your application uses and a handful of reserved
ranges. Additionally that available space is fragmented from those
mappings and reserved ranges such that the largest single allocation
you can make is around 2 GiB (assuming no other allocations have yet
further fragmented your virtual memory space).
You can use vmmap (man vmmap) to probe how you virtual memory is
allocated in your application.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden