digitalmars.D - Sharing memory with C, ref counting, best practises?
- Manu <turkeyman gmail.com> Apr 25 2012
- Walter Bright <newshound2 digitalmars.com> Apr 25 2012
--485b397dd775c68a6604be7cc59c Content-Type: text/plain; charset=UTF-8 I just wanted to sample community opinion on some modern best practices for sharing memory with C code. What have people tried, what works well, what doesn't? I need to produce objects which C++ code will use, and D code may lose all references to this memory at times. My current intent is to use a foreign allocator supplied from C++, allocating in the C++ heap, then perhaps use reference counting to track the life of the objects, since the GC won't be so useful in this context. My objects lend themselves better to ref counting anyway I think. Just to double check, D has no intrinsic support for ref counted classes does it? Are there best practises/standard implementations I should follow? Some sick part of me considered using COM, since lots of C++ code already knows how to interface COM. Thoughts? I have pre-conceptions here, I'm just looking for options + opinions on what might be best. --485b397dd775c68a6604be7cc59c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I just wanted to sample community opinion on some modern best practices for= sharing memory with C code.<div>What have people tried, what works well, w= hat doesn't?<br><br></div><div>I need to produce objects which C++ code= will use, and D code may lose all references to this memory at times.</div=
ocating in the C++ heap, then perhaps use reference counting to track the l= ife of the objects, since the GC won't be so useful in this context.</d= iv> <div>My objects lend themselves better to ref counting anyway I think.</div=<div><br></div><div>Just to double check, D has no intrinsic support for r=
ns I should follow?</div> <div><br></div><div>Some sick part of me considered using COM, since lots o= f C++ code already knows how to interface COM. Thoughts?</div><div><br></di= v><div>I have pre-conceptions here, I'm just looking for options + opin= ions on what might be best.</div> --485b397dd775c68a6604be7cc59c--
Apr 25 2012
On 4/25/2012 1:36 AM, Manu wrote:I just wanted to sample community opinion on some modern best practices for sharing memory with C code. What have people tried, what works well, what doesn't? I need to produce objects which C++ code will use, and D code may lose all references to this memory at times. My current intent is to use a foreign allocator supplied from C++, allocating in the C++ heap, then perhaps use reference counting to track the life of the objects, since the GC won't be so useful in this context. My objects lend themselves better to ref counting anyway I think. Just to double check, D has no intrinsic support for ref counted classes does it? Are there best practises/standard implementations I should follow? Some sick part of me considered using COM, since lots of C++ code already knows how to interface COM. Thoughts? I have pre-conceptions here, I'm just looking for options + opinions on what might be best.
I suggest using COM.
Apr 25 2012








Walter Bright <newshound2 digitalmars.com>