Hi all,

I have a proposal to add Deterministic Garbage Collector Pointer
Here is code example:
#include <iostream>
#include "gc_ptr.hpp"

class Child;

class Parent {
public:
Parent() {
std::cout << "Parent()" << std::endl;
}

~Parent() {
std::cout << "~Parent()" << std::endl;
}

void createChild() {
child_ptr_.create_object();
}

memory::gc_ptr<Child> getChild() {
return child_ptr_;
}

  // Could be generated by compiler
  void connectToRoot(void * rootPtr) {
child_ptr_.connectToRoot(rootPtr);
}

// Could be generated by compiler
void disconnectFromRoot(bool isRoot, void * rootPtr) {
child_ptr_.disconnectFromRoot(isRoot, rootPtr);
}

private:
memory::gc_ptr<Child> child_ptr_;
};

class Child {
public:
Child() {
std::cout << "Child()" << std::endl;
}

~Child() {
std::cout << "~Child()" << std::endl;
}

void setParent(memory::gc_ptr<Parent> parentPtr) {
parent_ptr_ = parentPtr;
}


// Could be generated by compiler
void connectToRoot(void * rootPtr) {
parent_ptr_.connectToRoot(rootPtr);
}

// Could be generated by compiler
void disconnectFromRoot(bool isRoot, void * rootPtr) {
parent_ptr_.disconnectFromRoot(isRoot, rootPtr);
}

private:
memory::gc_ptr<Parent> parent_ptr_;
};

int main() {
memory::gc_ptr<Parent> parent;
parent.create_object();
parent->createChild();
parent->getChild()->setParent(parent);
return 0;
}
Methods connectToRoot and disconnectFromRoot will be added by compiler
We would follow the Zero-overhead Principle

Here is the reference implementation:
https://github.com/redradist/DeterministicGarbagePointer

Also I have implemented draft generator for this library

Thanks,
Best Regards
Denis Kotov


--
Best Regards
Denis Kotov