> On Mon, 1 May 2000, Patrick Dughi wrote:
>
> > Now, if you - for some reason - want to allocate memory dynamically
> > for a multidimensional array, it gets complicated because dynamic
> > allocation of an n-dimensional array actually requires dynamic
> > allocation of n 1-dimensional arrays. To allocate a 2-dimensional
> > array one must first allocate memory sufficient to hold all the
> > elements of the array, then allocate memory for pointers to each row
> > of the array. A for loop will do this pretty well.
>
> You can treat an arbitrary dimensioned array as a single pointer of
> size x1 * x2 * ... * xN * sizeof(T). The only thing you need is a means
> to convert from any set of coordinates to a unique linear address. This
> is easy with two dimensions -- anyone who did graphics programming in the
> olden days should recognize this:
Yep - the biggest problem though is that you can't access and
throw it around like you can an array. It's quite easy to simulate
multidimensional arrays with what is, infact, a single array (or more
accurately, a single lump of contigious memory). I always think it's
better though to put off that huge amount of work with multiple macros
which to use eventually requires a decent amount of understanding about
how the system is setup. Granted, for most usage, something like
PSEUDO_ARRAY(arrayname,xcoor,yxoor,zcoor);
is pretty much the same as
arrayname[xcoor][ycoor][zcoor];
PjD
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/10/01 PDT