From D struct to C struct
Namespace
rswhite4 at googlemail.com
Sun Nov 17 16:22:09 PST 2013
On Sunday, 17 November 2013 at 22:25:54 UTC, qznc wrote:
> On Sunday, 17 November 2013 at 22:11:02 UTC, Namespace wrote:
>> Hello.
>> I have some trouble with C interfacing.
>> I have a C struct with an integer member and I want to wrap
>> this into a D template. But if I want to access the C API, I
>> have to convert the C struct with the type informations of the
>> D struct.
>> Example: http://dpaste.dzfl.pl/e3d10755
>>
>> The question is: How can I write the ptr method? It is very
>> probable, that these conversion is often used, so the ptr
>> method should be fast and without many garbage. And If
>> possible, I want to avoid the GC / Heap.
>> My current approach doesn't avoid the GC complete, but it
>> displace the problem: http://dpaste.dzfl.pl/449f663f
>>
>> Any further ideas how to solve that?
>
> You cannot use the stack due to your API requirements, so only
> heap or data segment remains. I assume you cannot use static
> variables, so heap it is. You should look into Andreis proposed
> std.allocator to optimize your memory management.
>
> http://forum.dlang.org/post/l4btsk$5u8$1@digitalmars.com
That reminds me: Even if I use the Heap, I cannot deal with a
const ptr method (because I must update the pointer), but
sometimes I have to. Therefore it isn't possible to declare a C
pointer inside of D.
So AFAIK there are only those two ways of me. Or did I miss
something?
More information about the Digitalmars-d-learn
mailing list