home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 20057 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  2.3 KB

  1. Path: sparky!uunet!noc.near.net!ceylon!choffman.gte.com!user
  2. From: chuck@gte.com (Chuck Hoffman)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Think C 32K segment
  5. Message-ID: <chuck-181292154535@choffman.gte.com>
  6. Date: 18 Dec 92 21:22:26 GMT
  7. References: <1go3ohINN4pq@network.ucsd.edu>
  8. Sender: news@ceylon.gte.com
  9. Followup-To: comp.sys.mac.programmer
  10. Distribution: usa
  11. Organization: GTE Laboratories
  12. Lines: 68
  13.  
  14. In article <1go3ohINN4pq@network.ucsd.edu>, sah@coast.ucsd.edu (Scott A.
  15. Herndon) wrote:
  16. >     Greetings,
  17. >         I am trying to write a program using ThinkC 5.x that
  18. >     declares a large array.
  19. >     int Height[129][129];
  20. >         I get the "code overflow" message when trying to compile
  21. >     and I think this has to do with some sort of 32k segment limitation.
  22. >     My questions are:
  23. >     i) Am I correct about the cause of the error?
  24. >     ii) How can I declare and use a large array like the one above
  25. >         that is about (2*129)^2 bytes large?
  26.  
  27. I would try an approach using NewHandle, to get the memory you need at
  28. execution time, instead of at compile time.  Then initiailize the array
  29. after you get it.
  30.  
  31. This code is off the top of my head, so take it with a pound or two of
  32. salt.  It does compile in a "main" segment, and with cursory checking
  33. (only) seems to run okay under THINK C 5.0.4:
  34.  
  35. typedef    struct    heightStruct
  36.     {    int    h1;
  37.         int h2;
  38.     }    **heightStructH;
  39.  
  40. heightStructH        myHeightStructH;
  41. int                    workH2;
  42. int                    j;
  43.  
  44. /*    get memory for structure:    */
  45.  
  46. myHeightStructH =
  47.         (heightStructH) NewHandle(129 * sizeof(struct heightStruct));
  48. /* check for bad return here, then continue    */
  49.  
  50. /* initialize the structure, possibly in a loop like this:    */
  51. for (j=0; j<129; j++)
  52.     {
  53.     (*(*myHeightStructH + j)).h1 = 0;        /* looks ugly, but...    */
  54.     (*(*myHeightStructH + j)).h2 = 0;        /* ...it's legitimate    */
  55.     }
  56.  
  57. /* later, to get info from element 5 ("j") of the structure:    */
  58.  
  59. j = 5;
  60. workH2 = (*(*myHeightStructH + j)).h2;
  61.  
  62. /* remember about locking/unlocking, and, when done, disposing    */
  63.  
  64.  
  65. Good luck.  Let me know how it comes out.
  66.  
  67. Chuck Hoffman
  68. chuck@gte.com
  69. GTE Laboratories, Waltham, Massachusetts, USA
  70. (617) 466-2131
  71. =====================================
  72. I'm not sure why we're here, but I am sure that while we're here we're
  73. supposed to help each other.
  74. =====================================
  75.