Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker.mit.edu!apple!well!oster From: oster@well.sf.ca.us (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: "Large" arrays in Think C Message-ID: <21918@well.sf.ca.us> Date: 2 Dec 90 16:21:24 GMT References: <1990Nov29.213603.12527@midway.uchicago.edu> Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 60 In article <1990Nov29.213603.12527@midway.uchicago.edu> kwhyte@arthur.uchicago.edu (Kevin Whyte) writes: > This must be a simple thing to do: I'm running on a Mac ][ >with 5 M, but Think C won't let me use arrays larger than about 64K! I am surprised you are seeing problems at 64k. THINK C complains if you try to allocate more than 32k of static data. The solution is to allocate it dynamically. For a one dimensional array that was originally: float floats1[1000]; change this declaration to: float *floats1; /* 1000 */ and put at the start of your program: floats1 = (float *) NewPtr(1000L * sizeof(float)); for a multidimnsional array that was originally: float floats3[10][9][8]; change this declaration to: typedef float FloatsRow[9][8]; FloatsRow **floats3; /* 10 */ #define sizeof_floats3 (10L*sizeof(FloatsRow)) and put at the start of your program: floats3 = (FloatsRow **) NewPtr(sizeof_floats3); for(i = 0;i < 10;i++){ floats3[i] = (FloatsRow *) NewPtr(sizeof(FloatsRow)); } in both cases, after this initial setup, the remainder of the program is unchanged. (provided that the remainder of the program has been recompiled with the new declarations of floats1 and floats3. You can get them initialized to zero by using NewClearPtr() instead of NewPtr(). If NewClearPtr is not defined in your version, it is: #include Ptr NewClearPtr(size)long size;{ asm{ move.l size,d0 _NewPtr CLEAR move.l a0, d0 } } In a real program, make sure that you declare: Ptr NewPtr(long); before you use it (and the same with NewClearPtr()). Make sure you check the value returned by NewPtr and if it NIL (i.e., NULL, or 0L). put up an error alert and quit. -- -- David Phillip Oster - At least the government doesn't make death worse. -- oster@well.sf.ca.us = {backbone}!well!oster