Using Boost POOL - singleton

I started using boost pools as singleton defined in boost / pool / singleton_pool.hpp, since I need to create many structures of the same size multiple times. The performance improvement is phenomenal since I used malloc before.

The objects that I select are put into the list by the producer thread, and the consumer stream transfers them from the other end and frees the objects. But when I free the object, the memory usage in the task manager never decreases. I assume this is due to the fact that a certain amount of memory is pre-allocated by the pool library?

Also, when the manufacturer's data rate increases, the total memory usage appears to increase in chunks of ~ 10k, but never decreases even after a free call for objects in the pool.

I would like some of the houses to be kept periodically to free up chunks of memory in order to reduce the overall memory usage in the process. Is it possible? I cannot use purge_memory, as this will mean that I will have to synchronize the cleaning between producers and consumers. BTW does purge_memory frees a piece, i.e. Reduces memory usage in task manager?

I program in MS windows.

Thanks Niladri

PS - I tried using release_memory, making the pool ordered (ordered_malloc), but always returns false.

UPDATE:

Do not try purge_memory while the pool is split between two threads. But they found that release_memory works, but only for ordered pools and slowly frees memory, since it frees only blocks of memory without allocation.

Cleaning will work faster. I'm sure.

+4
source share
3 answers

According to doc :

bool t.release_memory()

t need to order. Releases every memory block that has no allocated fragments. Returns true if at least one block of memory has been freed.

bool t.purge_memory()

Resets each memory block. This function invalidates any pointers previously returned by the distribution functions t. Returns true if at least one block of memory has been freed.

To free up memory, you need to use purge_memory() . You can only do this if every pointer that you get through the pool is no longer in use!

If release_memory returns true, it seems your memory is still in use ...

my2c

+3
source

This is how boost::pool works, and so your distributions are so faster. When you select an object, you are not really selecting anything. boost::pool basically says that the memory area is available for another object of this size. That way, no, you won’t see that your memory usage goes down when you free objects because it works with the pool of objects. You have a piece of predefined memory, and you use this piece of memory to create your objects. "Pool of objects" as if :)

+1
source

Do not try purge_memory while the pool is split between two threads. But they found that release_memory works, but only for ordered pools and slowly frees memory, since it frees only blocks of memory without allocation.

Cleaning will work faster. I'm sure.

0
source

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


All Articles