I thought to loosen the explicit memory management. But it turned out, it is not working as expected for multi-threaded scenarios.
At the moment, only unique managed pointers are working correctly by holding the ref count before passing the pointer. Shared pointers do not do that and are exposed to access a dangling pointer if the creator happened to release the resource after passing it.
The whole shared idea is completely useless and out of function at the moment.
Therefore. Passing managed pointers need two ways only to be handled:
// allows to freely pass around the pointer (borrowing)
some_funk( any_mtr_t )
{
// use pointer
}
// requires the pointer to be copied or moved. Also requires
// a release of the pointer.
some_funk( any_mtr_safe_t ptr )
{
// use or store pointer but requires a ...
motor::memory::release_ptr( ptr ) ;
// somewhere in the code of the receiver
}
So
the *_mtr_safe_t type signifies that the pointer is or needs to be storable and therefore needs to have its ref count incremented.
the *_mtr_t type is a plain pointer but signifies that it is managed.
the *_mtr_t type can be used to store the pointer because the purpose is known through the function argument through which the pointer has been passed
the *_mtr_t type also signals a "borrow" if used as a function argument
share() and unique() are used to pass the pointer by "copying" or "moving" the pointer. Meaning incrementing the ref count or take the refcount.
This all also means, that a stored _mtr_t pointer hides the intention of being shared or unique. But I didn't really ever used this idea when storing the pointer. The point here is that, shared or unique, the managed pointer needs to be released.
I thought to loosen the explicit memory management. But it turned out, it is not working as expected for multi-threaded scenarios.
At the moment, only unique managed pointers are working correctly by holding the ref count before passing the pointer. Shared pointers do not do that and are exposed to access a dangling pointer if the creator happened to release the resource after passing it.
The whole shared idea is completely useless and out of function at the moment.
Therefore. Passing managed pointers need two ways only to be handled:
First: How to pass on the resource
Second: What is the intention
So
*_mtr_safe_t
type signifies that the pointer is or needs to be storable and therefore needs to have its ref count incremented.*_mtr_t
type is a plain pointer but signifies that it is managed.*_mtr_t
type can be used to store the pointer because the purpose is known through the function argument through which the pointer has been passed*_mtr_t
type also signals a "borrow" if used as a function argumentshare()
andunique()
are used to pass the pointer by "copying" or "moving" the pointer. Meaning incrementing the ref count or take the refcount.This all also means, that a stored
_mtr_t
pointer hides the intention of being shared or unique. But I didn't really ever used this idea when storing the pointer. The point here is that, shared or unique, the managed pointer needs to be released.