home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / mac / programm / 18128 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.2 KB  |  63 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!darwin.sura.net!news.udel.edu!udel!sbcs.sunysb.edu!csws20.ic.sunysb.edu!rhorn
  3. From: rhorn@csws20.ic.sunysb.edu (Robert Horn)
  4. Subject: Re: How to use large arrays in Think C?
  5. Message-ID: <1992Nov7.192508.989@sbcs.sunysb.edu>
  6. Sender: usenet@sbcs.sunysb.edu (Usenet poster)
  7. Nntp-Posting-Host: csws20.ic.sunysb.edu
  8. Organization: State University of New York at Stony Brook
  9. References: <CSTROCKB.92Nov6235644@csws12.cs.sunysb.edu>
  10. Distribution: comp
  11. Date: Sat, 7 Nov 1992 19:25:08 GMT
  12. Lines: 49
  13.  
  14. In article <CSTROCKB.92Nov6235644@csws12.cs.sunysb.edu> cstrockb@cs.sunysb.edu (Caleb Strockbine) writes:
  15. >
  16. >Forgive me if I should have been able to figure this out on my own, but
  17. >deadlines are approaching and I need to get to work...
  18. >
  19. >I know that I can't declare arrays > 32K in Think C on the stack. Fine,
  20. >I don't mind using malloc(). But I'm working on a project for a class
  21. >in which I have to process images that are 256x256 pixels, and the images
  22. >are stored (on a unix system) as 256x256 byte files (each byte = 1 pixel).
  23. >
  24. >So my question is this: is it possible to allocate a bunch of memory using
  25. >malloc() and then pretend it's a regular array?
  26.  
  27. If you're using Think C 5.0.x, you can turn on the far data option, otherwise, you
  28. might be able to...
  29.  
  30. typedef struct Bongo Bongo, *BongoPtr;
  31. struct Bongo {
  32.   Byte        x[256][256];   // your data, Think C should be able to handle
  33.                  // this definition, just not a declaration
  34.                  // of the type. You can probably mess around
  35.                  // with typedefs and array types, I just don't
  36.                  // like the idea of a pointer to an array
  37.                  // and am not sure of how to code one.
  38. };
  39.  
  40. your_code() {
  41.   BongoPtr     pBongo;
  42.   short        i, j;
  43.  
  44.   pBongo = NewPtr(sizeof(Bongo)); // a call to malloc of > 32K is automaticly
  45.                   // a call to NewPtr, i believe
  46.   if(!pBongo) {
  47.     FailHorribly();
  48.   }
  49.   for(i = 0; i < 256; i++) {
  50.     for(j = 0; j < 256; j++) {
  51.       pBongo->x[i][j] = 0;      // init to 0, or use NewPtrClear
  52.     }
  53.   }
  54.   // your code here
  55. }
  56.  
  57. Cheers!
  58. Robb
  59. (official member of the michael kifer fan club)
  60. -- 
  61. rhorn@ic.sunysb.edu           Never choose a college because it has a duckpond.
  62. Would you like to touch my wombat?          Send me hate mail, I love it.
  63.