home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / msdos / programm / 11572 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.1 KB  |  75 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mcsun!sunic!dkuug!daimi!aau!psykseth
  3. From: psykseth@aau.dk (Seth Chaiklin)
  4. Subject: more on large global arrays
  5. Message-ID: <1992Dec22.100021.29719@aau.dk>
  6. Summary: code example of a large global array
  7. Keywords: try, try, again
  8. Organization: Aarhus University, Denmark
  9. Date: Tue, 22 Dec 1992 10:00:21 GMT
  10. Lines: 63
  11.  
  12. Thanks to several folks for replying to my recent request for help
  13. with a large global array.  I asked generally (and got a general answer).
  14. [In fact, there is nothing in FAQ about this, and maybe it is not a
  15. FAQ, but anyway I got some interesting and useful advice from various
  16. people that I would be willing to assemble for the FAQ keeper -- e.g.,
  17. that many C-library functions won't work on huge arrays]
  18.  
  19. Meanwhile...back to my problem...
  20. Now I will ask specifically, by showing what I am trying to do, and
  21. see if I can come any farther than crashing my system.  Sometimes the 
  22. following code seems to work, sometimes it doesn't.  Once I ran it inside
  23. of tc's debugger, and got an "internal error, please report to Borland"
  24. My honor does not lie in my C programming performance, fire away!
  25.  
  26. Thanks,
  27.   Seth Chaiklin
  28.   psykseth@aau.dk
  29. ----------Turbo C 2.0  compile with (tcc -mc) -----------
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <alloc.h>
  34.  
  35. int huge *yycrank;        /* huge pointer to be used for big array */
  36.  
  37. void main()
  38. {
  39.   int x, lx=0;
  40.   FILE *f;
  41.   long *cptr;
  42.  
  43. /* allocate some memory for the array */
  44.  
  45.   yycrank = (int huge *) farmalloc( 66000L * sizeof(int));  
  46.  
  47. /* make sure this did not bomb */
  48.  
  49.   if (yycrank==0)
  50.     {
  51.       printf("\nIkke nok RAM");
  52.       exit(1);
  53.     }
  54.  
  55. /* open file with  39386 positive digits (all under 200) and all on
  56.    a single line with spaces between them                          */
  57.  
  58.   if ( (f=fopen("bignum.","rt")) == NULL) {
  59.     fprintf(stderr, "\nFil ikke fandt");
  60.     exit(2);
  61.   }
  62.  
  63. /* read in the file to the allocated memory */ 
  64.   do {                  
  65.     x = fscanf(f,"%d", &cptr);
  66.     *(yycrank + lx) = (long) cptr;                
  67.     lx++;
  68.   } while (x != EOF);
  69.   
  70. /* Did I get through it all? */
  71.  
  72.   printf("laesede: %d", lx);
  73. }
  74.  
  75.