bearophile Wrote:

> Saaa:
> 
> > Is there a better way to support arrays of any type?
> > Currently all the code working with these Structs are templated with loads 
> > of static ifs in them.
> 
> You have to ask a more precise question if you want an answer.
Maybe a more general one :)
I use a tagged union scheme to encapsulate different types(arrays) as one type. 
Accessing the arrays thus always need a type-check, plus I need multiple 
get/setArray functions (or one template with loads of static ifs). 
Is there maybe a general scheme which results in the same type support without 
the all the separate type handling hassle?

> 
> > Also, is it possible to add a .deepdup property to all arrays?
> 
> D devs don't read posts here, so you have to ask ask in the main newsgroup. I 
> have asked for that more than a year ago, and I was ignored, as usual.

Two might not be a front, at least they make a line. 
 
> > Will "a[]=b.dup;" copy b twice?
> 
> When you have questions like this it's good to take a look at the produced 
> asm.
> The dup allocates a new array and then copies data on it.
> The a[]=b[]; copies b on a.
By 'copies b on a' you mean only the length and pointer, right.
How do you produce asm? Not that I can read it but it would be a nice way to 
start learning it a bit.
> 
> 
> > int[] array;
> > array.length = 100;
> > array.length = 0;
> > //no other arrays pointing/slicing to this array
> > This way I can be sure for the following 100 element concatenations
> > the array won't be copied.
> > Or isn't this implicitly part of the D spec? 
> 
> Are you talking about appends or concatenations? Concatenations produce 
> memory allocations. But you probably mean 100 appends. Those 100 appends will 
> not produce allocations or copies.
> But generally array appends are slow anyway in D, so where you need to do 
> them quickly it's much better to use an ArrayBuilder like the one in my 
> dlibs, of a similar one a bit less efficient in Phobos of D2.

Dlibs license doesn't like my commercial project :) 
(also, deprecated)

ByeBye and thanks,
Saaa

Reply via email to