Heap allocation and internal pointers

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Jan 20 11:58:12 PST 2014


20-Jan-2014 23:48, Steven Schveighoffer пишет:
> On Mon, 20 Jan 2014 11:35:10 -0500, Dmitry Olshansky
> <dmitry.olsh at gmail.com> wrote:
>
>> 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.
>
> I think this is somewhat too general. It can be GC allocated, even
> GC-array allocated. The GC will not move around your array unexpectedly
> without updating the pointers.

But a moving collector will happily assume there are no internal 
pointers when moving and won't update them I bet.



-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list