BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlbb_pooledblobbufferfactory

Detailed Description

Outline

Purpose

Provide a concrete implementation of bdlbb::BlobBufferFactory.

Classes

See also
bdlbb_blob, 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).

Thread Safety

The bdlbb::PooledBlobBufferFactory class is fully thread-safe (i.e., all non-creator methods can correctly execute concurrently). See bsldoc_glossary for complete definitions of fully thread-safe.

It is safe to access and modify factory from multiple threads. However, it is not safe to allocate and load a new buffer into the same BlobBuffer object simultaneously from multiple threads.

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.