Dynamic multidimensional arrays

Doug Gwyn gwyn at brl-smoke.ARPA
Thu Jun 16 18:13:46 AEST 1988


In article <3365 at ut-emx.UUCP> jjr at ut-emx.UUCP (Jeff Rodriguez) writes:
>In article <4556 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>>If you allocate the entire array (including space for the pointers as well as
>>the contents) in a single chunk, then you don't need all those free_array()
>>routines -- the standard free() will work.  I've written it this way.
>
>Quite true.  Another benefit is that the one can use one call to fread()
>to read a binary image from a file directly into one of these arrays.
>If each row is allocated with a separate call to malloc(), then the
>resulting array must be filled one row at a time.

Karl's point is that the "row vector" can be contiguous with the MxN data
area.  That is indeed a nice idea, and I think I'll change some of our
applications to do this.

fread() can fill the data area, but then people like me who've been
allocating separate row vector and MxN data areas could have done that
anyway.

Separate allocations for each row really would be pretty dumb, unless
several rows might be unneeded (I have an application like that, too).



More information about the Comp.lang.c mailing list