Re: Throwing bad_alloc when calling new on large class

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"SteveZ" <SteveZ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1DABCB7F-CA1A-4970-9FEB-6E6F08C2BDC2@xxxxxxxxxxxxxxxx


"Brian Muth" wrote:

Both these statements are incorrect. 32-bit WinXP uses up to 3.5 GB of
physical memory regardless of the /3G switch. Each
application has either 2G or 3G of virtual address space depending on
the switch, and each application can have nearly unlimited
virtual memory using file mappings.

Thanks for the correction


You mentioned these are static arrays? They shouldn't add to the
per-instance object size at all.


I'm not convinced the OP actually used to static keyword. If so, this is
indeed a surprise, since the actual allocation is probably
quite small, and one wouldn't expect a bad_alloc exception. Perhaps the
OP can clarify.

Brian




Brian is correct. It was a poor choice of words on my part in the OP. I
should have said that they are fixed-size arrays, not static arrays. So
they
are allocated each time the class is created with new.

Since I am not using the complete physical address space and I should have
plenty of virutal memory (as indicated by Ben Voigt), I am still confused
as
to why the allocation of the class is failing. I should also mention that
this exception occurs on the first occurance of class allocation and is
consistent between program runs. Can the heap be this fragmented every
time
I run the program?

Your virtual address space is pretty fragmented, because dynamic libraries
are compiled to use random locations in the hope of preventing collisions.
(If there were a collision the loader would have to fixup every reference to
code, global variable, etc which adds a lot of overhead to initializing a
DLL).


Thanks.
-SteveZ



.



Relevant Pages

  • Re: xmalloc string functions
    ... And the callbacks do one thing at a time, ... and even if you had infinite memory it's ... I try to write my code so any allocation failure is handled ... I don't need a gigantic switch statement, ...
    (comp.lang.c)
  • Re: stack overflow
    ... complier options and if for production better switch to heap based ... memory allocation... ...
    (comp.lang.cpp)
  • Re: the 3GB Switch?
    ... The Perils of Trying to Overcome the 2GB Memory ... Windows will not allow you to use more than 2GB for a single ... SolidWorks is written to take advantage of the 3GB switch. ...
    (comp.cad.solidworks)
  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH 00/28] Swap over NFS -v16
    ... memory they can consume. ... So we need the extra (skb) ... included in the reserve? ... if the allocation had to dip into emergency reserves, ...
    (Linux-Kernel)