Fwd: Re: [Dev-C++] Multidimensional arrays and memory leaks
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Paul I. <pi...@ot...> - 2004-08-10 23:46:07
|
>Hi, > >Since I tried to use a 2D array "number[50000][2]" I started to have ran= dom >=20 >crashes at run time and debugging.=20 > >I guess this is a memory handling problem (what do you think?). Sure, if you declared it like that.=20 Windows uses a dynamically growing stack. Just above the top of the stack= there is a read-only area. When the stack is growing (in resonable increments) = there will be a write to this area triggering an exception. This exception tell= s windows to increase the size of the stack, moving forward the stack-need-= to-grow read-only area.=20 Now if you declare something really big, there is a chance that you will = make a memory access missing the availabe stack (including the protective area). (This is absolutly not a windows-specific problem, BTW. Just about the sa= me everywhere...) > Thus, I tried >to put the array in the heap (would that help?). However I tried many wa= y to >do=20 >it without success.=20 > >I declared the array in the header of a class as: > >float number[][]; > >Then I tried to put it in the heap using GlobalAlloc in the constructor.= =20 GlobalAlloc ?? Thats some antique windows-API function from the 80286 day= s is't it? Why not use new? number =3D new float[50000*2]; /Paul ----- End forwarded message ----- |