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()))
Invoking copy c'tor!
Invoking copy c'tor!
Invoking copy c'tor!
<cppyy.gbl.UponCopyPrinter object at 0x78a7650> and <cppyy.gbl.UponCopyPrinter object at 0x78a7650>
<cppyy.gbl.UponCopyPrinter object at 0x78a7650> and <cppyy.gbl.UponCopyPrinter object at 0x7866ca0>
- Date
- May 2018
- Author
- Danilo Piparo
Definition in file vo001_AdoptOrOwnMemory.py.