home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!ncar!news.miami.edu!newssun.med.miami.edu!umbio.med.miami.edu!jack
- From: jack@umbio.med.miami.edu (Jack Herrington)
- Subject: Re: Large multidimensional arrays in C (THINK/MPW)???
- Message-ID: <1992Nov23.203639.7607@newssun.med.miami.edu>
- Sender: news@newssun.med.miami.edu
- Nntp-Posting-Host: umbio.med.miami.edu
- Organization: University of Miami Medical School
- References: <1992Nov23.161608.11712@nic.funet.fi>
- Date: Mon, 23 Nov 1992 20:36:39 GMT
- Lines: 32
-
- asunta@convex.csc.FI (Miika Asunta) writes:
- : Let's make a 1D array example...
-
- That works fine, but the problem I was having and maybe some other people is
- that NewHandle will bomb out on really large blocks. But that's not it's
- fault. For example, you have a 100 byte long structure, and you want 4000 of
- them. That's 40,000 bytes, normally you would just go like this:
-
- newHand = NewHandle(sizeof(theStruct)*4000);
-
- But that will fail because Think is going to think of both of those as shorts
- even though the product will be more than a short.
-
- So...
-
- long newHandSize = sizeof(theStruct) * 4000;
- newHand = NewHandle(newHandSize)
-
- Will work.
-
- As for two dimensional arrays, the normal way to do that is to write a little
- locator code that is like:
-
- Ptr ItemLoc(Ptr basePtr,short numCols,short rowNum,short colNum)
- {
- return basePtr + ( ( ( numCols * rowNum ) + colNum ) * sizeof(Item) );
- }
- }
- --
- "Down in Joe's garage, we didn't have no dope, or LSD. But a couple o'
- quarts of beer would fix it so the intonation would not offend your ear"
- -Frank Zappa
-