Reuse C memory for D struct?

Lemonfiend lemon at fie.nd
Thu Nov 21 09:57:31 PST 2013


On Thursday, 21 November 2013 at 17:12:26 UTC, evilrat wrote:
> On Thursday, 21 November 2013 at 15:22:10 UTC, Lemonfiend wrote:
>> Hi!
>>
>> I'm wondering if it's possible to have a struct in D which 
>> uses the same pointer and memory as returned by the extern C 
>> function.
>> This would allow me to manipulate and use the C struct 
>> directly in D code.
>
> so what really stops you from accessing that pointer in D?
Well right now, in the code above, the original C pointer is 
lost, only the D pointer remains.

> if you fear for data layout just wrap this pointer in D struct 
> and give properties to accessing stuff from pointer(weird)
Yes a solution would be to simply store the C pointer in the D 
struct, but then the C and D structs are no longer the same.


More information about the Digitalmars-d-learn mailing list