refInt = ref int: how to achieve this? or is this a bug?

mw mingwu at gmail.com
Thu Jun 18 01:21:52 UTC 2020


On Thursday, 18 June 2020 at 00:40:15 UTC, Stanislav Blinov wrote:
> That's completely backwards. Because the C lib only takes 
> void*, it forfeits any type safety and memory safety, so it is 
> *on you* to preserve that. Which would require quite some code 
> indeed. I don't think you've fully considered the implications 
> of your code.

Thank you for your comments.

But I think you complicated the design: C is C, D is D. So let

-- C manage C's memory (the container), and
-- D manage C's memory (the objects)

The only thing interfacing is simple the (void*) as *value*.

-- all primitive types | class (pointers)'s *value* are stored as 
value of (void*)
-- all (fat) objects' *address* are stored as value of (void*)

The only extra requirement on the D side is to keep reference to 
those fat objects to avoid it being GC-ed before being pop-ed.

(Just as don't push a stack var into any-type-of queue, and pop 
it after the stack is gone -- this are the responsibility of the 
programmer, not the container.)

That's all.

Anyway, this is a bit off-topic of this thread. Feel free to 
comment on github after I finish it, and welcome to be my code 
reviewers.




More information about the Digitalmars-d mailing list