Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think!husc6!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.c Subject: Re: 2d arrays in C Message-ID: <929:May3000:09:3990@stealth.acf.nyu.edu> Date: 30 May 90 00:09:39 GMT References: <4273@munnari.oz.au> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Organization: IR Lines: 19 In article <4273@munnari.oz.au> ok@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