Re:Rust and C++ Interoperability in Chrome
by Paul-ish on Wednesday August 19, 2020 @09:15PM
(#24218852)
Inside both Rust and C++ there are very well developed tools (eg smart pointers) for dealing with memory allocations. These tools were never written to be compatible with each other, so you lose them at the language boundary.
Re:Rust and C++ Interoperability in Chrome
by xxpor on Thursday August 20, 2020 @12:26PM
(#24224916)
That makes sense. I do 99% C, so any time I even have to think about C++ it unfortunately turns into C with classes rather than C++, so I'm really not as familiar with the smart pointer options.
Re:Rust and C++ Interoperability in Chrome
by webkike on Wednesday August 19, 2020 @03:51PM
(#24215381)
There are some things that make this better, such as returning pointer types and not returning raw pointers. Returning raw pointers usually means that another function will delete them. I very rarely see pointers handed back from functions being freed caller side
Re:Rust and C++ Interoperability in Chrome
by Matthias247 on Wednesday August 19, 2020 @04:13PM
(#24215698)
Do you mean references instead of pointers? I'm not familiar of a difference between pointers and raw pointers in C or C++.
C++ allows to be more clear: unique_ptrs allow to move ownership, references mean this is definitely not owned, and the remaining questions are around normal pointers.
With pure C there is however zero distinction. A pointer can mean ownership is transferred, it is meant to be a reference, it could be a static reference to something in constant memory, etc.
Re:Rust and C++ Interoperability in Chrome
by webkike on Wednesday August 19, 2020 @05:15PM
(#24216609)
I meant pointers versus types such unique_ptr and shared_ptr
Re:Rust and C++ Interoperability in Chrome
by Snelius on Wednesday August 19, 2020 @10:32PM
(#24219285)
You will lost his (*_ptr) magic cuz types match is not compatible. Mem must be free on the allocation side, kind of law.
Re:Rust and C++ Interoperability in Chrome
by edflsafoiewq on Wednesday August 19, 2020 @04:14PM
(#24215714)
RAII usually handles all that.
Isn't this an issue regardless? Forget crossing the rust/c++ boundary, lets say you pass something to another class in c++, you need to have a contract of who frees what when, right? Maybe I'm not understanding the issue.