home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18830 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.6 KB  |  45 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. 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
  3. From: jack@umbio.med.miami.edu (Jack Herrington)
  4. Subject: Re: Large multidimensional arrays in C (THINK/MPW)???
  5. Message-ID: <1992Nov23.203639.7607@newssun.med.miami.edu>
  6. Sender: news@newssun.med.miami.edu
  7. Nntp-Posting-Host: umbio.med.miami.edu
  8. Organization: University of Miami Medical School
  9. References: <1992Nov23.161608.11712@nic.funet.fi>
  10. Date: Mon, 23 Nov 1992 20:36:39 GMT
  11. Lines: 32
  12.  
  13. asunta@convex.csc.FI (Miika Asunta) writes:
  14. : Let's make a 1D array example...
  15.  
  16. That works fine, but the problem I was having and maybe some other people is
  17. that NewHandle will bomb out on really large blocks.  But that's not it's 
  18. fault.  For example, you have a 100 byte long structure, and you want 4000 of
  19. them.  That's 40,000 bytes, normally you would just go like this:
  20.  
  21. newHand = NewHandle(sizeof(theStruct)*4000);
  22.  
  23. But that will fail because Think is going to think of both of those as shorts
  24. even though the product will be more than a short.
  25.  
  26. So...
  27.  
  28. long newHandSize = sizeof(theStruct) * 4000;
  29. newHand = NewHandle(newHandSize)
  30.  
  31. Will work.
  32.  
  33. As for two dimensional arrays, the normal way to do that is to write a little
  34. locator code that is like:
  35.  
  36. Ptr ItemLoc(Ptr basePtr,short numCols,short rowNum,short colNum)
  37. {
  38.     return basePtr + ( ( ( numCols * rowNum ) + colNum ) * sizeof(Item) );
  39. }
  40. }
  41. -- 
  42. "Down in Joe's garage, we didn't have no dope, or LSD.  But a couple o'
  43.  quarts of beer would fix it so the intonation would not offend your ear"
  44.         -Frank Zappa
  45.