Is there any way to check if array is dense or not?

bearophile bearophileHUGS at lycos.com
Mon Nov 11 07:00:18 PST 2013


Mariusz `shd` Gliwiński:

> So it's not contigous http://dpaste.dzfl.pl/7c5d2fa8 ?

That's usually not contiguous. But even a dynamic matrix can have 
contiguous (untested):

auto raw = new int[9];
auto m = new int[][](3);
m[0] = raw[0 .. 3];
m[1] = raw[3 .. 6];
m[2] = raw[6 .. 9];


> 1. I'd like to use `1 memcpy(m*n)` instead of `m memcpy(n)`.

In idiomatic D code it's much better to avoid unsafe C functions 
(untested), this only works withe the contiguous matrix:

data[] = m[0].ptr[0 .. m.length * m[0].length];


> The goal is to use contigous arrays in every case when i don't 
> need to resize inner arrays.

If you use a dynamic array of fixed-sized arrays this is often 
not possible, because often you know the sizes only at run-time. 
So in this case you need slices, as I have shown above.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list