Re: Another question about multidimentional arrays



Ron Francis wrote:
I have wondered what the benefit is to using multidimensional arrays.

They represent the abstractions in your model correctly.

Isn't
int arr[10][10];
basically the same as
int arr[100];

The type is different, but the contents (and the memory they occupy) are essentially the same.

Is the only benefit in how you visual the array in your mind in columns and rows?

Mmm... It's all in the algorithms you use.

Is there any speed gain in using a single dimensional array?

No, and it's usually a rather huge loss when it comes to code clarity and maintainability. The point of having the two dimensions is that your algorithms are so much clearer when you allow the compiler to do the actual resolving of the indices.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.



Relevant Pages

  • Bit manipulation
    ... One question about the bit manipulation: if the code is like: ... is that mean, in memory, although generally for int, it occupy 32 bits, ...
    (comp.lang.c)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)
  • [PATCH 8/19] TuxOnIce: Add core TuxOnIce code.
    ... Add the core TuxOnIce code, including hooks in snapshot.c so TuxOnIce ... can use the atomic copy and restore functions, ... +extern int toi_running; ... * system memory to an arbitrary storage device, either on the local computer, ...
    (Linux-Kernel)
  • [RFC][PATCH 08/12] memory hotplug: sysfs and add/remove functions
    ... This adds generic memory add/remove and supporting functions ... extern int devices_init; ... +void unregister_memory_notifier ... +/* reasonably generic interface to expand the physical pages in a zone */ ...
    (Linux-Kernel)