Re: Visual C++ and large 2d arrays
On May 3, 7:10 am, ico.buk...@gmail.com wrote:
Could it be something like the problem described at the following link
even though I am using "new" to allocate memory?
http://www.daniweb.com/techtalkforums/thread46297.html
No, or at least not directly.
I'm not sure what your version of VC++ does if new fails because
of insufficient memory. The standard says you get an exception,
and the latest versions of VC++ are conform, but VC++ 6.0 still
returned a null pointer (when it detected the situation). For
starters, you might try 1) wrapping your code in a try block,
and catching std::bad_alloc, and 2) testing the result of each
new for NULL. Realistically, however: at around 100, you're
allocating under 50 KB; I can't imagine that failing on any
modern machine.
Greg Hilary's suggestion about char overflowing is interesting
as well. Logically, it should mean a threashold of exactly 128,
however. Still, if you compile using unsigned char (option /J,
I think), you should be able to eliminate it.
Other than that, I don't see anything wrong with it. I just ran
it on my PC (a very small machine, with only 256 MB), and had no
problems with numvoices at 100000; at 1000000, the program
became very slow, as the machine started paging, and I finally
got a bad_alloc exception. (This is with VC++ 2005.)
All I can suggest is that you try to isolate a 15-20 line bit of
code which can be compiled on its own, and manifests the error,
and post that.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34