Provide a concrete implementation of bdlbb::BlobBufferFactory
.
More...
Namespaces |
namespace | bdlbb |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a concrete implementation of
bdlbb::BlobBufferFactory
.
-
- Classes:
-
- See also:
- Component bdlbb_blob, Component bdlma_concurrentpool
-
- Description:
- This component provides a mechanism for allocating
bdlbb::BlobBuffer
objects of a fixed specified size. The size is passed at construction of the bdlbb::PooledBlobBufferFactory
instance. A bdlbb::BlobBuffer
is basically a shared pointer to a buffer of char
of the prescribed size. Thus it is generally more efficient to create them with a uniform size, for the same reason as a pool is more efficient than a general-purpose memory allocator. In order to gain further efficiency, this factory allocates the shared pointer representation together with the buffer (contiguously).
-
- Potential Lifetime Issues:
- Be aware that the destruction of a
bdlbb::PooledBlobBufferFactory
object releases all the BlobBuffer
objects allocated by that factory. A common misconception is that, because of the use of shared_ptr
, the data referred to in BlobBuffer
objects created will remain valid until the last shared reference is destroyed, even if a reference outlives the PooledBlobBufferFactory
that created it. This is not the case. Destroying a PooledBlobBufferFactory
releases any memory created by that pool, even if shared references remain to the data, and it is therefore undefined behavior to use any BlobBuffer
created by a pool after that pool is destroyed. A user must clearly understand the lifetime of memory allocated by a subsystem, and scope the lifetime of the PooledBlobBufferFactory
to be greater than the active lifetime of that subsystem.