On Tuesday, 7 February 2017 at 20:33:35 UTC, Ali Çehreli wrote:
On 02/07/2017 02:11 AM, Bastiaan Veelo wrote:
> We do not need to take measures against the GC?
Of course we have to and the struct that I wrote is illegal
because it is self-referencing through the _ptr member. (D has
the right to move structs around, making my _ptr potentially
pointing to an illegal address.)
Gosh am I glad I brought that up, and for people like you hanging
out in the learn group. Thanks for pointing this out!
This optimization cannot work if the array is a static array
inside the same struct. It would work with a dynamic array but
then it would probably be slower than applying the *(ptr+index)
technique.
You mean slower than the _payload[index - first] technique? Is
that because of heap memory versus stack memory?
Am I correct that the reason that a dynamic array would work is
because it is allocated independently from the struct, meaning
that its address stays the same even if the struct is moved? We
could .reserve a dynamic array in initialize() to prevent it
being resized.
Thanks again.
Bastiaan.