On 27/08/2010 9:38 a.m., bearophile wrote:
Arrays are one of the most useful and most efficient data structures for 
nonfunctional languages. They look simple, but in a low-level language you 
sometimes need various kinds of them. So they are not so simple.

In D there are two kinds of built-in arrays:
A) 1D Dynamic arrays on the heap
B) Almost-nD rectangular fixed-sized arrays allocated on the stack by functions 
(or data segment), they may also go on the heap if they are part of an object 
(and with placement new they may go everywhere).

So far in D code I have had need of (and I have seen some people need) some 
other kinds of arrays, not (well) supported by D:
C) nD rectangular dynamic arrays;
D) Dynamic arrays allocated on the stack;
E) Fixed-sized arrays allocated on the heap;
F) Variable-sized structs allocated on the heap.

----------------------

The (C) arrays are not the same thing as dynamic arrays of dynamic arrays 
because:
- Some algorithms are not designed for a triangle where rows may differ in 
length. Testing that rows are all the same length at runtime wastes time, and 
if you don't test it then it may cause bugs;
- Sometimes you want to reshape a 2D matrix, so it's useful to store the matrix 
in contiguous memory;
- Sometimes you need complex slicing, for example removal of some columns and 
rows from a 2D matrix.


Bearophile

Have you got any numbers to back your claim for increased performance for nD rectangular dynamic arrays ?

I too, am interested in them, but would like to use them with Tango, and therefore if there was a increase in performance, and therefore a real benefit, then would ask that they be added to the D language, so that all in the D community could benefit.

Nick B

Reply via email to