Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!henry.ECE.CMU.EDU!hairston From: hairston@henry.ECE.CMU.EDU (David Hairston) Newsgroups: comp.sys.mac.programmer Subject: Re: Arrays bigger than 32K. Message-ID: <12529@pt.cs.cmu.edu> Date: 30 Mar 91 02:27:14 GMT References: <1991Mar29.185449.4477@bingvaxu.cc.binghamton.edu> Distribution: usa Organization: Gaia II Lines: 79 [kap1@phyllis.math.binghamton.edu (Dietrich Kappe) writes:] [] Attempted Solution: [] [] typedef short thingType[60][60][8]; [] thingType *thing; [] ... [] thing=(thingType *)lmalloc(sizeof(thingType)); [] [] Of course I still get an illegal array limits error on the typedef [] statement. The compiler needs the array bounds for pointer arithmatic, [] and I certainly don't want to do all those pointer operations by hand. [] Any ideas on how I can get arround the 32K size limit without giving up [] array dimmension information? hmm, this comes up from time to time so i'll post here where it may do more good. you could try an approach like this (extreme, but you should get the point): the innermost dimension is a pointer to an array of pointers (to an array of pointers to short integers). let's call this dimension, dim1 and generate the following typedefs: typedef short ***dim1; typedef short **dim2; typedef short *dim3; or better yet: typedef short *dim3; typedef dim3 *dim2; typedef dim2 *dim1; hopefully you see that the outer dimension is the only one that really points to a specific data type (short). the inner dimensions are merely pointers to pointers. now you can get away with something like this: #define D1 60 #define D2 60 #define D3 8 dim1 thing; short i, j, k; thing = (dim1) malloc(D1 * sizeof(dim2)); /* ... check to see if malloc was okay */ for (i = 0; i < D1; ++i) { thing[i] = (dim2) malloc(D2 * sizeof(dim3)); /* ... check to see if malloc was okay */ } for (i = 0; i < D1; ++i) for (j = 0; j < D2; ++j) { thing[i][j] = (dim3) malloc(D3 * sizeof(short)); /* ... check to see if malloc was okay */ } if you're concerned with zero-initialization you can now do: for (i = 0; i < D1; ++i) for (j = 0; j < D2; ++j) for (k = 0; k < D3; ++k) { thing[i][j][k] = 0; /* ... or if your'e concerned with pointer math */ *( *( *( thing + i ) + j ) + k ) = 0; } i said at the outset that this example was extreme. it is also non-optimal but i leave it to you to optimize to taste. one thing to keep in mind, although "thing" now looks like a three dimensional array, it isn't! for example, you can't do ANSI memset()-like commands on this object. in all other respects, tho, it behaves like a three dimensional array. -dave- hairston@henry.ece.cmu.edu