Artur Schütz
Artur Schütz

Reputation: 3

bad_alloc even though I have lots of memory available

I am trying to subdivide a sphere recursively to implement a spherical wavelet algorithm on the faces. While I have 8 GB on memory available, I am limited to 9 subdivision levels for an icosahedron. My problem is the lack of memory and a bad_alloc exception while building my sphere even when I have plenty of memory available.

I thought I would reach my limit at 4 GB for a Win32 application because I would run out of addressable memory pointers. But as you can see I reached the limit at about 1.9 GB.

This error is independent from the used system.

Out of Memory (Screenshot)

Does anybody know what happened and how to deal with this kind of problem?

Upvotes: 0

Views: 1773

Answers (1)

Steve Townsend
Steve Townsend

Reputation: 54128

You will never be able to get 4GB allocated because that's the entire available memory space for a 32-bit process. This includes code and other data, of which there will be some to support (for example) the runtime library and stack, even if your executable allocates no other blocks.

On Windows you can get more than 2GB allocated only by linking your binary with the LARGEADDRESSAWARE flag. There is brief explanatory information in the MSDN documentation.

This limitation can be avoided by building your app as a 64-bit executable, assuming you can target only 64-bit Windows machines.

There is more background on memory limits for a given Windows version here. If you are stuck with 32-bit, PAE may be useful.

Upvotes: 4

Related Questions