Heap allocation and internal pointers
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Jan 19 15:02:25 PST 2014
On 1/19/14 8:18 AM, monarch_dodra wrote:
> What is the "stance" on objects that reside on the heap, and internal
> pointers?
>
> I understand that for stack objects, it leads to data corruption, due to
> data being bit-moved when passed around.
>
> But what about heap data? Currently, our GC doesn't move data around,
> but what if it did? Would internal pointers be a problem? How do java/C#
> handle such cases?
>
> 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.
>
> Would this be legal in D? The alternative would simply be to have two
> separate sentinels. It wouldn't change the design much, but I'd like to
> avoid doing it if at all possible...
A moving collector should preserve the semantics of your object.
Andrei
More information about the Digitalmars-d
mailing list