Change representation of dynamic arrays?

Witold Baryluk baryluk at smp.if.uj.edu.pl
Sat Oct 20 09:21:19 PDT 2007


Dnia Fri, 19 Oct 2007 20:03:02 -0700
Walter Bright <newshound1 at digitalmars.com> napisał/a:

> Currently, arrays are represented under the hood as:
> 
> 	size_t lengthOfArray;
> 	void* ptrToStartOfArray;
> 
> Which works out reasonably well. The problem is if you want to use
> array types as the basis of iterators, and you want to step through
> the array. There's no escaping it being two operations:
> 
> 	decrement the length
> 	increment the pointer
> 
> This puts a brick in any fast implementation of iterators. To fix
> that, we can change the representation to:
> 
> 	void* ptrToStartOfArray;
> 	void* ptrPastEndOfArray;
> 
> Then there's just one increment. Some tests show this can improve
> loop performance by up to 70%.

What about garbage collector? And pointer that doesn't points to
real data?

If this will be fixed somehow and there will be strategy for
moving collector to change this obscure second pointer to be proper, for
new location of data, then it can be good choice. (especially if this
change of iterator really will increse iteration, and wouldn't give
regressions).


-- 
Witold Baryluk, aleph0



More information about the Digitalmars-d mailing list