Array append performance
bearophile
bearophileHUGS at lycos.com
Mon Aug 25 09:51:30 PDT 2008
Benji Smith:
> So, while a stride field seems very useful for some very interesting
> special cases, to me it seems like the more compelling general case is
> for a memoized hashcode.
Rectangular 2D arrays enjoy a stride as 4th field, while (usually 1D) strings enjoy having a hash value there. The two cases are very distinct, with rare mixed cases.
So an ugly idea: if the 4th array is 1D the field can be the hash value, if it's 2D it can contain the stride ;-) (But if superdan is right, all this discussion may need to be re-built on different basis).
On the other hand, the capacity field isn't much useful for 2D arrays (because you usually append to 1D arrays), so you end with just 3 fields with 2D arrays and 4 fields for 1D arrays :-) So, if you want to keep both structures of len 4 (assuming pointers and size_t having the same size) you can add a second stride, useful for 3D arrays too ;-)
Bye,
bearophile
More information about the Digitalmars-d
mailing list