-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Garbage collector for c++ version #14
Comments
Thank you! You have just saved me a whole lot of work! I've really got to find some time to finish this off. |
I've switched over I'm getting Seg Faults at the moment. However the gc.h and gc.cpp files are tiny, so it shouldn't take long to figure out the bugs. |
I think I have a design mistake: |
In the old days when I was developing games, we solved this by just marking objects to be freed (using a simple double linked list or so), and then in a second phase actually freeing the memory, without any other side effects. Not sure if this applies here, I don't know the details. |
@ziriax that applies here. I've just realized that it is the purpose of the |
What I really need to do is a proper test suit for
|
The existing C++ version of Sodium was one of my earlier efforts and it has a lot of not-so-good attempts at optimization. I'd like to see it re-written in a much simpler way, more along the lines of the Typescript version. I'd love to see it work with move semantics instead of passing a pointer to the value around. But this isn't the priority. The priority it getting it working! |
The TypeScript version is really tidy, and I now find it easy to understand. I think people can wait for a TypeScript to C++ translation if that is where we will end up going. We should have the sodium objects lazyly construction like in the TypeScript version, but remove the requirement for all sodium object to be listened to in order to work correctly. I believe we can achieve this in C++ because we have automatic reference counting (a stack). |
What is the canonical version?
GR
…Sent from my Nexus 6P
On 26 Feb 2018 09:18, "Clinton Selke" ***@***.***> wrote:
The TypeScript version is really tidy, and I now find it easy to
understand. I think people can wait for a TypeScript to C++ translation if
that is where we will end up going.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEy9nFFvWhcy4YEYqMxvBs80RK8y6gN6ks5tYnbegaJpZM4SL9Rd>
.
|
@grahamreeds the canonical version is the latest version in https://github.com/SodiumFRP/sodium-cxx/releases at the moment. @the-real-blackh We need to implement finalizers to avoid that seg fault I had before. Why? Because the deconstructor executes methods on objects being referenced by the deconstructing object. |
Finalizers are now supported in gc-cxx (see tests/test_gc.cpp for usage). It won't be as simple as string replacing std::shared_ptr / std::weak_ptr. Some destructor code will need shuffling too. |
Something has just occurred to me. In order to support lazy construction of the sodium object graph, you would be forced to listen to all sodium objects for them to be updated correctly ( I completely understand why we are forced to listen to all sodium objects in TypeScript. Because we really have no choice, its our only means of reference counting. In C++ & Rust we have automatic reference counting, we can do better. Lets just try and get the current C++ version working as is first. And refactor in the move semantics as we go. |
Great! I didn't know there was a way to do it with GC. I agree - If we can use that, then it would definitely be better. |
I've made a bit of a start of at integrating I also just saw |
magic_ref.h was an experimental attempt to do something along these lines - I can't remember exactly what. |
@the-real-blackh
I've translated "Gc.rs" from Rust to C++ . It is designed to work exactly the same way as the rust one. It uses the template struct
Trace
to mimic aTrace
trait.https://github.com/clinuxrulz/gc-cxx
If this is the sort of approach you would like to use, then maybe it could find a home in "SodiumFRP/.." somewhere.
The strategy in mind for use is:
WeakGc<>
forward references,Gc<>
back references. The back references tend to get held in the cleanup/finalizers of the sodium objects.Trace
implementations would need to be provided for Cell/Stream and Listener to use it. (I.E. Anywhere aGc<>
could be held needs to be made reachable byTrace<>::trace(...)
)Here is what it looks like when you use it:
https://github.com/clinuxrulz/gc-cxx/blob/master/example.cpp
The example creates a cycle among 3 objects and shows them getting freed at the end of the local scope.
The text was updated successfully, but these errors were encountered: