The following code fragment produces a memory access conflict at seemingly random points during the loop, depending on which testfile is used. It always occurs during the Smooth function and the error is “Attempted to read or write protected memory”. If the line tree->GetEntry(loop) is removed, then there are no errors. Any help would be appreciated.
TFile* file = new TFile(“testfile.root”);
TTree* tree = (TTree*)file->Get(“tree”);
MyClass* car = new MyClass;
tree->SetBranchAddress(“branch”, &car);
Attached is a simplified version of the class I used, as well as the main function. This produces the same error as described above. Thanks in advance for the help. MyClass.h (869 Bytes) main.cpp (1.76 KB) MyClass.cpp (1.97 KB)
The problem is that you do not initialize the pointer data member of your class in the default constructor. Hence the value of those data member are random and when the ROOT I/O uses them, the result is also random (hence the core dump). So use something like:MyClass::MyClass()
{
//Default Constructor
fNumberOfPoints = 0;
fProfile1 = 0;
fProfile2 = 0;
etc..
Cheers,
Philippe
Thank you very much for the help. As for valgrind, I don’t have access to a Linux box where I work. Is there something similar I could use that runs on Windows XP?
I followed your suggestion and initialized all of the pointers to 0 in my default constructor. However, I’m still experiencing the same error. I attached the updated version of MyClass. MyClass.cpp (2.2 KB)