Skip to content

Internal Fragmentation #2

Description

@hohaidang

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions