ACLiC garbage collector

Hi,

Is there anyway to turn the ACLiC garbage collector off?

Here is an example of code which works in a less than ideal manner,

std::vector<std::string> *vec = 0;
TFile *f = 0;

void getVector(const char *vecName, std::vector<std::string> someVec) {
  vec = (std::vector<std::string>*)f->Get(vecName);
  if(vec) std::cout << "The vector is okay here" << std::endl;
}

void myFunction() {
  f = TFile::Open("somefile.root");
  getVector("vec",vec);
  if(!vec) std::cout << "ACLiC garbage collector in action" << std::endl;
}

The variable “vec” is valid inside the function, but is null afterwards. The work around is to copy the vector elements, which is wasteful in terms of CPU.

Best regards,

Will

Hi,

This seems unrelated to ACLiC per se but instead it seems to be a C++ question.

The code as is (beside the missing #include) does not compile and issue the expected: .../vec.cxx:10: warning: unused parameter ‘someVec’ .../vec.cxx: In function ‘void myFunction()’: .../vec.cxx:17: error: conversion from ‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*’ to non-scalar type ‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >’ requested i686-apple-darwin10-g++-4.2.1: .../vec_cxx_ACLiC_dict.o: No such file or directory

The code itself is very confusing it pass the global ‘vec’ to a function: getVector("vec",vec);but then the function ignore the parameter completely and use the global variable instead: vec = (std::vector<std::string>*)f->Get(vecName);

[quote]The variable “vec” is valid inside the function, but is null afterwards.
[/quote]depending how the code in the real case look like htis might or might not be the expected result (due to the double use of the global variable.

I am guessing the following does what you really want:[code]std::vectorstd::string *vec = 0;
TFile *f = 0;

void getVector(const char *vecName, std::vectorstd::string &someVec) {
// Since somevec is a C++ reference to a pointer, the pointer passed as argument to the function will be modified.
someVec = (std::vectorstd::string
)f->Get(vecName);
if(someVec) std::cout << “The vector is okay here” << std::endl;
}

void myFunction() {
f = TFile::Open(“somefile.root”);
getVector(“vec”,vec);
if(!vec) std::cout << “ACLiC garbage collector in action” << std::endl;
}[/code]

Cheers,
Philippe.

Hi,

After some more experimentation, it seems that the clean up of cloned objects is a constant and is nothing to do with ACLiC. The use case is

void function(TH1F *h_in, TH1F *h_out) {
  if(!h_out) h_out = (TH1F*)h_in->Clone("some_name");
}

void another_function() {
  TH1F *h_in = new TH1F("h_in","",10,0.,10.);
  TH1F *h_out = 0;
  function(h_in,h_out);
  if(!h_out) std::cout << "The histogram pointer is still null" << std::endl;
}

if the pointer h_out is null before the function call, then it is defined in the function and then null after the function. In my recent test setup no global variables were used. The Cloned class is deleted when the function finishes. This is somewhat confusing since, returning a pointer would seem to suggest that the object is created on the stack.

Thanks and best regards,

Will

[code]void function(TH1F *h_in, TH1F **h_out) {
if(h_out && !(*h_out)) (h_out) = ((TH1F)(h_in->Clone(“some_name”)));
}

void another_function() {
TH1F *h_in = new TH1F(“h_in”,"",10,0.,10.);
TH1F *h_out = 0;
if (h_in) h_in->Print();
function(h_in, &h_out);
if(!h_out) std::cout << “The histogram pointer is still null” << std::endl;
else h_out->Print();
}[/code]

void function(TH1F *h_in, TH1F *h_out) {This is the C++ syntax to pass the pointer by value, within the function, h_in and h_out are local variable and any changes to their value will not be reflected in the value of the callers’ variable. If you want to change the callers’ variable value, you need to pass a pointer to the variable (i.e a pointer to a pointer in this case, see Pepe’s post for example) or by you can pass them by reference.

Cheers,
Philippe.