2d arrays in C

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Wed May 30 10:09:39 AEST 1990


In article <4273 at munnari.oz.au> ok at mudla.cs.mu.OZ.AU (Richard O'Keefe) writes:
> We've had a lot of fun arguing about what dynamic arrays in C _should_
> look like and whether it's doable.  To be really helpful and productive,
> I thought I'd share a README file with you.  (One fine point:  the data
> structure used here for 2d arrays would **NOT** work with fwrite.)

One fine point: The reason its 2d arrays wouldn't work with fwrite is
that it implemented them as pointers to pointers to data. In contrast,
when 2d arrays are implemented as huge square chunks addressed by a
single pointer, they work *perfectly* with fwrite. The same applies to
3d arrays implemented as huge cubic chunks, etc.

(Of course, one method may be more or less efficient on different
machines: multiple pointers use more memory accesses, while true
multidimensional arrays use more CPU calculation, plus even more memory
if registers aren't free for variable dimensions. I'd use multiple
pointers on a microcomputer, true arrays on a real computer.)

---Dan



More information about the Comp.lang.c mailing list