home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!mcsun!sunic!dkuug!daimi!aau!psykseth
- From: psykseth@aau.dk (Seth Chaiklin)
- Subject: more on large global arrays
- Message-ID: <1992Dec22.100021.29719@aau.dk>
- Summary: code example of a large global array
- Keywords: try, try, again
- Organization: Aarhus University, Denmark
- Date: Tue, 22 Dec 1992 10:00:21 GMT
- Lines: 63
-
- Thanks to several folks for replying to my recent request for help
- with a large global array. I asked generally (and got a general answer).
- [In fact, there is nothing in FAQ about this, and maybe it is not a
- FAQ, but anyway I got some interesting and useful advice from various
- people that I would be willing to assemble for the FAQ keeper -- e.g.,
- that many C-library functions won't work on huge arrays]
-
- Meanwhile...back to my problem...
- Now I will ask specifically, by showing what I am trying to do, and
- see if I can come any farther than crashing my system. Sometimes the
- following code seems to work, sometimes it doesn't. Once I ran it inside
- of tc's debugger, and got an "internal error, please report to Borland"
- My honor does not lie in my C programming performance, fire away!
-
- Thanks,
- Seth Chaiklin
- psykseth@aau.dk
- ----------Turbo C 2.0 compile with (tcc -mc) -----------
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <alloc.h>
-
- int huge *yycrank; /* huge pointer to be used for big array */
-
- void main()
- {
- int x, lx=0;
- FILE *f;
- long *cptr;
-
- /* allocate some memory for the array */
-
- yycrank = (int huge *) farmalloc( 66000L * sizeof(int));
-
- /* make sure this did not bomb */
-
- if (yycrank==0)
- {
- printf("\nIkke nok RAM");
- exit(1);
- }
-
- /* open file with 39386 positive digits (all under 200) and all on
- a single line with spaces between them */
-
- if ( (f=fopen("bignum.","rt")) == NULL) {
- fprintf(stderr, "\nFil ikke fandt");
- exit(2);
- }
-
- /* read in the file to the allocated memory */
- do {
- x = fscanf(f,"%d", &cptr);
- *(yycrank + lx) = (long) cptr;
- lx++;
- } while (x != EOF);
-
- /* Did I get through it all? */
-
- printf("laesede: %d", lx);
- }
-
-