In this tutorial we learn how the RVec class can be used to adopt existing memory or allocate some.
import ROOT
ROOT.gInterpreter.Declare('''
class UponCopyPrinter {
public:
UponCopyPrinter() = default;
UponCopyPrinter(UponCopyPrinter &&) = default;
UponCopyPrinter(const UponCopyPrinter &) { std::cout << "Invoking copy c'tor!" << std::endl; }
};
''')
RVec_UponCopyPrinter = ROOT.ROOT.VecOps.RVec(ROOT.UponCopyPrinter)
v = RVec_UponCopyPrinter(3)
v2 = RVec_UponCopyPrinter(v.data(), v.size())
print("%s and %s" %(v.data(), v2.data()))
v2.resize(4)
print("%s and %s" %(v.data(), v2.data()))
<cppyy.gbl.UponCopyPrinter object at 0x7ec86e0> and <cppyy.gbl.UponCopyPrinter object at 0x7ec86e0>
<cppyy.gbl.UponCopyPrinter object at 0x7ec86e0> and <cppyy.gbl.UponCopyPrinter object at 0x7dccfc0>
- Date
- May 2018
- Author
- Danilo Piparo
Definition in file vo001_AdoptOrOwnMemory.py.