TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS J. PEDERSEN
from: JOHN RICHARDSON
date: 1998-05-10 13:52:00
subject: memory allocation

Hi Thomas,
 > If I remove the static, and initialize the arrays myself, I get the
 > message "_Limit exceeds 64K"  or  "Abnormal program termination "
 > 
 > Obviously, the size of the arrays exceeds a predefined limit  ??.
What's happening here is that when you declare a variable, space is reserved 
for it on the stack, the stack is always of a predetermined size, in your 
case 64k. You can increase (or reduce) the size of the stack, the method will 
depend on your compiler, check the manual. Some use the system variable 
__STACK.
Another way around this, some would say a better way, is to dynamically 
allocate the memory required using malloc or new.
For example:
 >      static  double tabel[p];
becomes:
        double    *tabel = malloc( p );
and
 >      static  double Umat[p][p];
becomes:
         double   *Umat = malloc( p*p );
Access in the first case is as normal; tabel[x]. However in the second you 
need to do a little fiddling; 
         Umat[x][y]; 
 becomes:
         Umat[ x*p + y];
Admittedly this is the C way of doing it, there maybe better ways for C++.
John.
--- JetMail 0.99beta23
---------------
* Origin: The Dysfunctional Refrigerator (fidonet 2:2502/60)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.