home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!ceylon!choffman.gte.com!user
- From: chuck@gte.com (Chuck Hoffman)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Think C 32K segment
- Message-ID: <chuck-181292154535@choffman.gte.com>
- Date: 18 Dec 92 21:22:26 GMT
- References: <1go3ohINN4pq@network.ucsd.edu>
- Sender: news@ceylon.gte.com
- Followup-To: comp.sys.mac.programmer
- Distribution: usa
- Organization: GTE Laboratories
- Lines: 68
-
- In article <1go3ohINN4pq@network.ucsd.edu>, sah@coast.ucsd.edu (Scott A.
- Herndon) wrote:
- >
- >
- > Greetings,
- >
- > I am trying to write a program using ThinkC 5.x that
- > declares a large array.
- >
- > int Height[129][129];
- >
- > I get the "code overflow" message when trying to compile
- > and I think this has to do with some sort of 32k segment limitation.
- > My questions are:
- >
- > i) Am I correct about the cause of the error?
- > ii) How can I declare and use a large array like the one above
- > that is about (2*129)^2 bytes large?
- >
-
- I would try an approach using NewHandle, to get the memory you need at
- execution time, instead of at compile time. Then initiailize the array
- after you get it.
-
- This code is off the top of my head, so take it with a pound or two of
- salt. It does compile in a "main" segment, and with cursory checking
- (only) seems to run okay under THINK C 5.0.4:
-
- typedef struct heightStruct
- { int h1;
- int h2;
- } **heightStructH;
-
- heightStructH myHeightStructH;
- int workH2;
- int j;
-
- /* get memory for structure: */
-
- myHeightStructH =
- (heightStructH) NewHandle(129 * sizeof(struct heightStruct));
- /* check for bad return here, then continue */
-
- /* initialize the structure, possibly in a loop like this: */
- for (j=0; j<129; j++)
- {
- (*(*myHeightStructH + j)).h1 = 0; /* looks ugly, but... */
- (*(*myHeightStructH + j)).h2 = 0; /* ...it's legitimate */
- }
-
- /* later, to get info from element 5 ("j") of the structure: */
-
- j = 5;
- workH2 = (*(*myHeightStructH + j)).h2;
-
- /* remember about locking/unlocking, and, when done, disposing */
-
-
- Good luck. Let me know how it comes out.
-
- Chuck Hoffman
- chuck@gte.com
- GTE Laboratories, Waltham, Massachusetts, USA
- (617) 466-2131
- =====================================
- I'm not sure why we're here, but I am sure that while we're here we're
- supposed to help each other.
- =====================================
-