Heap allocation and internal pointers

monarch_dodra monarchdodra at gmail.com
Mon Jan 20 11:25:19 PST 2014


On Monday, 20 January 2014 at 16:35:26 UTC, Dmitry Olshansky 
wrote:
> You could use internal pointers for this case as long as:
> a) The struct will never get copied and/or moved. No pass by 
> value, only pointers.
> b) It's out of GC control and in particular GC-allocated 
> built-in arrays.
>
> This means you don't have that much of choice beyond things 
> like:
> MyObject* node = (MyObject*)malloc(MyObject.sizeof);
>
> And only ever using pointers.

Hum... well this contradicts Andrei's:

> A moving collector should preserve the semantics of your object.

I want to do:

//----
Node* root = new Node;
root._next = root;
root._prev = root;
//----

So in this case, it would perfectly go with your "A" 
recommendation. It's "B" I'm unsure of :/


More information about the Digitalmars-d mailing list