What I want to achieve is a object, which is shared among the threads of a benchmark and whose life time starts, when the benchmark starts and ends, when the benchmark is finished.
Currently I use a fixture and create the object in the constructor (Setup and Teardown is called too often). However this creates the object before the program's main, which can be the first problem. I can avoid that problem by moving BENCHMARK_REGISTER_F to the main. Still the created object is unconfigurable by command line arguments. RegisterBenchmark could help here.
However I fail to see a way to destroy the object at the proper time even when using RegisterBenchmark. If I run a lot of benchmarks, I might leak too much memory.
I'd like to see an enhanced RunBenchmark:
RunResults RunBenchmark(
const benchmark::internal::BenchmarkInstance& b,
std::vector<BenchmarkReporter::Run>* complexity_reports) {
b.benchmark->StartRunning();
internal::BenchmarkRunner r(b, complexity_reports);
b.benchmark->FinishRunning();
return r.get_results();}
StartRunning and FinishRunning are newly introduced virtual functions, which would solve my problem, since the benchmark object itself is shared.
Are there other ways to control the lifetime of shared objects?