C++ Logo

STD-DISCUSSION

Advanced search

Subject: Exposing the layout used by allocate_shared
From: Kwasi Mensah (kwasi.mensah_at_[hidden])
Date: 2019-06-13 13:23:33


Has there been any thought to to exposing the layout used by
std::allocate_shared (even through std::aligned_storage so as no to reveal
the internals)?

Context:
I'm trying to make a cached pool the gives out std::shared_ptr<T>. Even if
I cache the memory for T, I still hit memory allocations for the
std::shared_ptr control block and that slows things down.

Right now to get around this, I use std::allocate_shared with a custom
allocator that caches the allocation and checks to make sure that the same
size/alignment is always asked for. This requires two allocations: 1) for
the memory used for allocator_shared and 2) representing each pool entry
with the pointer to 1) and other bookkeeping data.

If I could statically know the layout of 1), I could make it part of the
allocation for 2).

This would make the standard require that std::allocate_shared only uses
one allocation (it current recommends it but doesn't force it).



STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups