Can IndexedMemPool support multiple types?

33 views
Skip to first unread message

PX

unread,
May 13, 2016, 9:59:06 AM5/13/16
to Folly: the Facebook Open-source LibrarY

Greetings,


I'm trying to implement a concurrent object pool for objects of various types. All object sizes are assumed to be less than a certain unknown threshold (see MAX_OBJ_SIZE) that will be provided later.

Upon creation pool capacity should be objects. When its capacity drops below objects, its capacity should be asynchronously replenished back to . The method may be called from any thread so it must be thread safe. When pool is completely depleted, i.e. replenishment can’t keep up with allocations, objects can be allocated using std::allocator.

Once object is allocated, its life scope is fully controlled by the shared pointer(s) containing the object. When the last of them goes out of scope, the object should be deleted and the memory allocated for the object should be automatically reclaimed by the pool. Object destruction may happen on any thread, not necessarily on the same thread that called .

A sample interface looks like this:
"
template <std::size_t MAX_OBJ_SIZE>
class pool {
 public:
  pool (std::size_t maxCapacity, std::size_t minCapacity);

  template <typename OBJECT, typename ...ARGS>
  std::shared_ptr<OBJECT> alloc(ARGS …args);
  ...
};
"

I've looked into IndexedMemPool but can't figure out how to support different types of objects, although all objects are smaller than MAX_OBJ_SIZE. Do you guys think this is possible with IndexedMemPool?

Thanks in advance,
PX

Reply all
Reply to author
Forward
0 new messages