Multithreaded Combined Distributors

I am having problems using distributed memory allocations for std :: list objects in a multi-threaded application.

The part of the code I'm connected to runs each thread function in isolation (i.e. there is no communication or synchronization between threads), and so I would like to set up separate memory pools for each thread, where each pool is not thread-safe (and therefore quick).

I tried using a single-user shared memory streaming pool and found that performance was low, as expected.

This is a very simplified version of the type of thing I'm trying to do. Much has been included in the pseudo-code view, sorry if this is confusing.

/* The thread functor - one instance of MAKE_QUADTREE created for each thread
 */
class make_quadtree
{
private:

/* A non-thread-safe memory pool for int linked list items, let say that it 
 * something along the lines of BOOST::OBJECT_POOL
 */
    pooled_allocator<int> item_pool;

/* The problem! - a local class that would be constructed within each std::list as the
 * allocator but really just delegates to ITEM_POOL
 */
    class local_alloc
    {
    public :
    //!! I understand that I can't access ITEM_POOL from within a nested class like
    //!! this, that really my question - can I get something along these lines to
    //!! work??
        pointer allocate (size_t n) { return ( item_pool.allocate(n) ); }
};

public :
    make_quadtree (): item_pool()    // only construct 1 instance of ITEM_POOL per
                                     // MAKE_QUADTREE object
    {
    /* The kind of data structures - vectors of linked lists
     * The idea is that all of the linked lists should share a local pooled allocator
     */
        std::vector<std::list<int, local_alloc>> lists;

    /* The actual operations - too complicated to show, but in general:
     *
     * - The vector LISTS is grown as a quadtree is built, it size is the number of
     *   quadtree "boxes"
     *
     * - Each element of LISTS (each linked list) represents the ID of items
     *   contained within each quadtree box (say they're xy points), as the quadtree
     *   is grown a lot of ID pop/push-ing between lists occurs, hence the memory pool
     *   is important for performance
*/
    }
};

, , , std:: list.

+3
2

local_alloc make_quadtree?

0

, , .

. , , hoard (hoard.org). , .

  • malloc, , .

, boost:: pool boost:: threadspecificptr. IMHO, ++, , , .

, , , , .

, , . , , , . , , , .

- , , . , , , . , std:: multiset , : STL

- , , , .

0

Source: https://habr.com/ru/post/1783978/


All Articles