Visual C++ 2005 heap size

Started by
4 comments, last by Agony 17 years, 5 months ago
I was making a little project in VC++ 6.0 and decided to start using the newer VC++ express edition instead. Once I eventually got everything compiling and linking the program now throws a std::bad_alloc exception at a new statement. This I gather means it couldn't allocate memory. I understand the default heap size is 1MB and my program could well be exceeding this, although there is plenty of available physical memory. So on the face of it you'd think that increasing the heap reserve would fix the problem but it hasn't. I've tried doing this by changing the Project Properties->Linker->System->Heap Reserve Size, but to no avail, it doesn't even seem to change the point in the program at which the exception is thrown. So my questions are, does anyone have a good link that explains the difference between heap reserve and heap commit and such? I've been struggling to find one. Also, is what I suggested sufficient for increasing heap allocation in VC++? And could anything else be causing my program to be having memory allocation failures? (Also the VC++ properties is asking for the size in bytes, not kb or anything else?)
Advertisement
The stack may be limited to 1MB by default. The heap most certainly isn't (on x86). You've almost certainly corrupted memory by writing through a bad pointer, double deleting, accessing an array out of bounds, etc. Does you debugger give you any additional information?

Σnigma
The full message from the debugger is:

'LastStraw.exe': Loaded 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\LastStraw\debug\LastStraw.exe', Symbols loaded.
'LastStraw.exe': Loaded 'C:\WINNT\system32\NTDLL.DLL', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\winmm.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\USER32.DLL', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\GDI32.DLL', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\KERNEL32.DLL', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\ADVAPI32.DLL', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\rpcrt4.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\opengl32.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\msvcrt.dll', No symbols loaded.
'LastStraw.exe': Loaded 'C:\WINNT\system32\glu32.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\ddraw.dll', No symbols loaded.
'LastStraw.exe': Loaded 'C:\WINNT\system32\dciman32.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\mmdrv.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Unloaded 'C:\WINNT\system32\mmdrv.dll'
'LastStraw.exe': Loaded 'C:\WINNT\system32\indicdll.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\imm32.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Loaded 'C:\WINNT\system32\nvoglnt.dll', No symbols loaded.
The thread 'Win32 Thread' (0x488) has exited with code 0 (0x0).
'LastStraw.exe': Loaded 'C:\WINNT\system32\mcd32.dll', Cannot find or open a required DBG file.
'LastStraw.exe': Unloaded 'C:\WINNT\system32\mcd32.dll'
First-chance exception at 0x77f9c677 in LastStraw.exe: 0xC0000005: Access violation writing location 0x00000448.
First-chance exception at 0x7c59bc81 in LastStraw.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012faf8..
Unhandled exception at 0x7c59bc81 in LastStraw.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012faf8..
The program '[996] LastStraw.exe: Native' has exited with code 0 (0x0).

I don't know about all these missing dbg files, but I would have thought that was a side issue. The std::bad_alloc exception was originally thrown in a method I have for recursively initialising node objects in my quad tree. This intialisation proceeds up to a certain point and then fails, if I reduce the number of levels in my quad tree then a similiar exception is thrown in a completely different part of the code when making a new unit object. I don't see what could be causing this.
I'd worry about this one first:
First-chance exception at 0x77f9c677 in LastStraw.exe: 0xC0000005: Access violation writing location 0x00000448

It looks like you're trying to dereference a NULL pointer somewhere, perhaps a dynamically allocated array (because of the largish size of the offset from NULL). I'm not sure why this one isn't bring your program crashing down before the std::bad_alloc, do you have a catch(...) somewhere that doesn't rethrow?
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
First-chance exception at 0x77f9c677 in LastStraw.exe: 0xC0000005: Access violation writing location 0x00000448.

This is your real problem. It seems you're trying to write to a location that is 1096 bytes offset from a NULL (0) pointer. Check all your pointer accesses, and make sure that you're never reading from a NULL pointer, or an offset from a NULL pointer (such as a member variable, or an array access).
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Actually, I suppose since it is with memory allocation, it almost certainly is as Enigma said. You're probably corrupting the heap somewhere, and then the system's memory allocation function is doing the write violation, because it's reading corrupted data. Either way, you're writing to memory that you shouldn't be writing to at some point before this crash. As Enigma said, probably a bad/random/uninitialized/already deleted pointer, out of bouds array access, or some such.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement