Click to See Complete Forum and Search --> : I can't allocate more than 16 bytes


jonnyt
February 26th, 2003, 12:43 AM
I just recently installed Visual Studio .NET and I am trying to run a program that worked fine before...

I cannot allocate more than 16 bytes on the heap.

If I go:

new int[5] I get a nomem exception, but

new int[4] works.

However

new int[4] ... new int[1] throws an exception.

This is the first memory I allocate. If I try to allocate more than 16 bytes on the heap at all I run out of memory. However I have 128MB on my system, and I had no trouble allocating before I install VC++ 7. Plus, I can allocate as much space as I want on the stack, with not problem.

I am at my wits end. I cannot find any reason for this problem to occur. I hope someone will have some knowledge?

-Jonny T

Bengi
March 3rd, 2003, 02:19 AM
try Malloc, or HeapAlloc() or GlobalAlloc()
if those also fails, than your system is low on memory, although nowdays windows uses Vmemory with swap..so..i can't tell much of the prob.

jonnyt
March 3rd, 2003, 02:56 PM
I figured out the problem. After many painful hours, I found the error in some code I had long ago decided was correct.

Basically I was overunning an array during static initialization. In VC++ 6 this had overwritten harmless memory (it seems), but in VC++ 7 it must have corrupted the heap manager. So, when I tried to allocate, even as the first line of my main function it failed. Weird.

It took me forever to find, since this code was compiled into a library long ago and seemed to have worked up till now.