[Issue 4092] broken memory management for COM objects derived from IUnknown
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 15 23:20:55 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4092
--- Comment #5 from Rainer Schuetze <r.sagitario at gmx.de> 2011-02-15 23:18:19 PST ---
Overloading new seems to do the job without the patch in the runtime, so here
is my current implementation of COM objects:
extern (C) void* gc_malloc( size_t sz, uint ba = 0 );
class ComObject : IUnknown
{
new(uint size)
{
void* p = gc_malloc(size, 1); // BlkAttr.FINALIZE
return p;
}
override HRESULT QueryInterface(in IID* riid, void** ppv) { ... }
override ULONG AddRef()
{
LONG lRef = InterlockedIncrement(&count);
if(lRef == 1)
GC.addRoot(cast(void*) this);
return lRef;
}
override ULONG Release()
{
LONG lRef = InterlockedDecrement(&count);
if (lRef == 0)
GC.removeRoot(cast(void*) this);
return cast(ULONG)lRef;
}
LONG count = 0; // object reference count
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list