Path: utzoo!utgpu!news-server.csri.toronto.edu!ephemeral.ai.toronto.edu!ai.toronto.edu!dudek Newsgroups: comp.sys.mac.programmer From: dudek@ai.toronto.edu (Gregory Dudek) Subject: Re: Need large array on Think C. Message-ID: <90May28.094000edt.8323@ephemeral.ai.toronto.edu> Organization: Department of Computer Science, University of Toronto References: <265986A9.26645@paris.ics.uci.edu> <5506@hub.ucsb.edu> Distribution: usa Date: 28 May 90 13:41:12 GMT Lines: 78 In article <5506@hub.ucsb.edu> stoms@castor.ncgia.ucsb.edu () writes: >In article <265986A9.26645@paris.ics.uci.edu> jchoi@paris.ics.uci.edu (John Choi) writes: >> Sorry for this trival question, but I really need to get this >>done. When I declare an array ('char arr[100][300]'), the complier >>gives me an 'illegal array bounds' error. Is there any way I can >>increase this limit? > > >When you want lots of variable space >32K in Think C or any compiler >that limits globals to 32K, you have to use the Memory Manager (gasp!). >If you want a big array, such as "char arr[100][400]" then you need to >sever your dependancy from the compiler and get your hands dirty. > >To allocate this array: > >char *arr; > >arr = NewPtr((Size)100*400); > >Then to use the array you can index like this: >x = 20; y = 32; >*(arr+x+y*100) = 'H'; > >Thats it! If you want to use a handle the only big difference is: >*(*arr+x+y*100) << note the extra * >> > >If you do this, be sure to lock down the handle when your r.h.s. could Although the method above works fine, I find it a bit ugly. Not only does sticking in calls to NewPtr explicitly lose portability, but the indexing scheme is much less readable than regular arrays. Finally, you may want to have the arrays initialized to zero, like ``real'' ones. I prefer the following scheme which is much more isomorphic to the commonly used sytax. Note, also, that since the arrays are allocated using pointers not handles, no locking down of memory is required at any time. 1) Add this header code: ======================= #define DCLARRAY(type,name,y,x) type *name[y] #define INITARRAY(type,name,y,x) allocate(name,(int)sizeof(type),y,x) allocate(array,elementsize,y,x) char *array[]; int elementsize; int y,x; { register int ix, iy; for (iy=0;iy