multithreading_cpp
multithreading_cpp copied to clipboard
Internal Fragmentation
Hello ourash, Thanks for the tutorials. I have an comment on file functors_main.cc.
for (int i = 0; i < number_of_threads; i++) { AccumulateFunctor *functor = new AccumulateFunctor(); threads.push_back( std::thread(std::ref(*functor), i * step, (i + 1) * step)); functors.push_back(functor); }
You create new AccumulatorFunctor in for loop. It will lead to internal fracmentation because it has to allocate 10 (headers) everytime the new is call. Instead of that you can allocate 10 memory before the loop
AccumulateFunctor *functors = new AccumulateFunctor[number_of_threads];
This one will save more memory (1 header is created only)