multithreading - Reducing the number of heap allocations when enqueuing tasks -


heap allocations bottleneck in application , avoid them when sending small tasks thread pool.

can use std::packaged_task stack allocator? under conditions? pros/cons of choice? there better alternatives avoid heap allocations of std::future's shared state operator new ?

auto foo() {   arena<1024> buffer;   auto task = std::packaged_task<int()>{     std::allocator_arg_t,      arena_allocator{arena},     []() -> int { return 5; }    };   auto f = task.get_future();  // future , shared state stack allocated?   thread_pool.push_back(std::move(task));    // need block before stack goes out of scope..   return f.get(); } 

your "i need block before stack goes out of scope" comment identifies issue here. thing must make sure because task in sending thread's stack, has stay there until thread pool executes it.

other that, there no issues using stack, instead of heap allocation.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -