home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!spool.mu.edu!darwin.sura.net!news.udel.edu!udel!sbcs.sunysb.edu!csws20.ic.sunysb.edu!rhorn
- From: rhorn@csws20.ic.sunysb.edu (Robert Horn)
- Subject: Re: How to use large arrays in Think C?
- Message-ID: <1992Nov7.192508.989@sbcs.sunysb.edu>
- Sender: usenet@sbcs.sunysb.edu (Usenet poster)
- Nntp-Posting-Host: csws20.ic.sunysb.edu
- Organization: State University of New York at Stony Brook
- References: <CSTROCKB.92Nov6235644@csws12.cs.sunysb.edu>
- Distribution: comp
- Date: Sat, 7 Nov 1992 19:25:08 GMT
- Lines: 49
-
- In article <CSTROCKB.92Nov6235644@csws12.cs.sunysb.edu> cstrockb@cs.sunysb.edu (Caleb Strockbine) writes:
- >
- >Forgive me if I should have been able to figure this out on my own, but
- >deadlines are approaching and I need to get to work...
- >
- >I know that I can't declare arrays > 32K in Think C on the stack. Fine,
- >I don't mind using malloc(). But I'm working on a project for a class
- >in which I have to process images that are 256x256 pixels, and the images
- >are stored (on a unix system) as 256x256 byte files (each byte = 1 pixel).
- >
- >So my question is this: is it possible to allocate a bunch of memory using
- >malloc() and then pretend it's a regular array?
-
- If you're using Think C 5.0.x, you can turn on the far data option, otherwise, you
- might be able to...
-
- typedef struct Bongo Bongo, *BongoPtr;
- struct Bongo {
- Byte x[256][256]; // your data, Think C should be able to handle
- // this definition, just not a declaration
- // of the type. You can probably mess around
- // with typedefs and array types, I just don't
- // like the idea of a pointer to an array
- // and am not sure of how to code one.
- };
-
- your_code() {
- BongoPtr pBongo;
- short i, j;
-
- pBongo = NewPtr(sizeof(Bongo)); // a call to malloc of > 32K is automaticly
- // a call to NewPtr, i believe
- if(!pBongo) {
- FailHorribly();
- }
- for(i = 0; i < 256; i++) {
- for(j = 0; j < 256; j++) {
- pBongo->x[i][j] = 0; // init to 0, or use NewPtrClear
- }
- }
- // your code here
- }
-
- Cheers!
- Robb
- (official member of the michael kifer fan club)
- --
- rhorn@ic.sunysb.edu Never choose a college because it has a duckpond.
- Would you like to touch my wombat? Send me hate mail, I love it.
-