0

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?

  • It depends how big the object was you were trying to allocate. Note that if the object uses contiguous memory (e.g. `std::vector`) you would need to have a *contiguous* block of memory available. So even if you had 1 GB of memory available, and requested a 0.75 GB block, that doesn't mean a *contiguous* 0.75 GB block is available, so it might throw. – Cory Kramer Feb 15 '17 at 13:29
  • related/dupe: http://stackoverflow.com/questions/5686459/what-is-the-maximum-memory-available-to-a-c-application-on-32-bit-windows – NathanOliver Feb 15 '17 at 13:29

1 Answers1

4

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.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • Wow, thank you. That solved my problem. I did not know 32-bit applications were bound to 2 GB memory caps without this flag. – Artur Schütz Feb 15 '17 at 13:52
  • I am thinking about to build my app as a 64-bit executable, but at the moment I have some 32-Bit dependencies which I would need to remove or replace. – Artur Schütz Feb 15 '17 at 13:58