Heap allocation and internal pointers

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Jan 20 08:35:37 PST 2014


20-Jan-2014 20:35, Dmitry Olshansky пишет:
> 19-Jan-2014 20:18, monarch_dodra пишет:

>> My usecase is pretty trivial: A linked list. This is often implemented
>> as a "single" sentinel that serves as both pre-head/post-tail. When the
>> list is empty, the sentinel simply points to itself.
>>
>
> 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);
>
s/(MyObject*)/cast(MyObject*)/

Too much of C on me lately ;)


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list