On Monday, 28 July 2014 at 21:33:54 UTC, Rene Zwanenburg wrote:

If I understand you correctly, an easy way is to use RefCounted with a simple wrapper. Something like this:

// Descriptor defined by the external library
struct DescriptorImpl
{
  size_t type;
  void* data;
}

// Tiny wrapper telling the alien GC of the existence of this reference
private struct DescriptorWrapper
{
  DescriptorImpl descriptor;
  alias descriptor this;

  @disable this();

  this(DescriptorImpl desc)
  {
    // Make alien GC aware of this reference
  }

 ~this()
  {
    // Make alien GC aware this reference is no longer valid
  }
}

// This is the type you will be working with on the D side
alias Descriptor = RefCounted!DescriptorWrapper;

Just read RefCounted definition here,
http://dlang.org/phobos/std_typecons.html#.RefCounted
and it heap allocates its object, so your response above does not stack allocate the basic type that you call DescriptorWrapper, and is not a solution to the problem as stated.

If there was no alien GC, but everything else was the same, heap allocation of something containing a DescriptorImpl would be unnecessary. Now achieve the same with the alien GC present without an extra layer of indirection and heap allocation --- this is the essence of my question.

Reply via email to