Follow up of attached discussion after more investigation.  I created an
example of returning Cache as shared pointer versus raw value:

    https://github.com/dgkimura/geode-native-sandbox

I still like returning by value as it lets the user do what they want with
their object.

    // Here user creates object on their stack.
    auto c = CacheFactory::createFactory().create();

    // Here user creates smart pointer in their heap.
    auto cptr =
std::make_shared<Cache>(CacheFactory::createFactory().create());

Difficulty of implementing this is high due to circular dependencies of
Cache/CacheImpl as well as objects hanging off CacheImpl that return
Cache.  We must be extra careful when dealing with move/copy semantics of
Cache/CacheImpl.

Alternative, is to keep as is and only permit heap allocations from factory
using shared pointers.

Thanks,
David

Reply via email to