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

Detailed Description

Outline

Purpose

Provide a simple implementation of bdlbb::BlobBufferFactory.

Classes

Description

This component provides a mechanism, bdlbb::SimpleBlobBufferFactory, that implements the bdlbb::BlobBufferFactory protocol and creates bdlbb::BlobBuffer objects of a fixed sized specified at the time the factory is constructed. The blob buffers created by this factory refer the a (shared) buffer allocated by the allocator supplied at construction, or the default allocator if no allocator is explicitly supplied.

Usage

In this section we show intended usage of this component.

Example 1: Simple Blob Buffer Factory

Suppose we want to make a blob that can be grown via calls to setLength, meaning that it must have a factory, and suppose you want all the memory for the blob buffers created for the factory to be allocated directly from a certain test allocator for test purposes. We use a SimpleBlobBufferFactory.

First, we create our allocator:

bslma::TestAllocator testAllocator;
Definition bslma_testallocator.h:384

Then, we create our factor using that allocator:

bdlbb::SimpleBlobBufferFactory factory(1024, &testAllocator);
assert(factory.bufferSize() == 1024);
Definition bdlbb_simpleblobbufferfactory.h:135

Next, we create our blob using that factory:

bdlbb::Blob blob(&factory);
Definition bdlbb_blob.h:642

Next, we set the length big enough to require 20 blob buffers:

blob.setLength(1024 * 20);

Then, we verify that the memory came from testAllocator. Note that since the blob buffers contain shared pointers, additional memory other than the writable areas of the blob buffers is allocated:

assert(1024 * 20 < testAllocator.numBytesInUse());
bsls::Types::Int64 numBytesInUse() const
Definition bslma_testallocator.h:1111

Now, we examine the state of the blob:

assert(20 == blob.numDataBuffers());
assert(20 == blob.numBuffers());
assert(1024 * 20 == blob.length());

Finally, we examine the blob buffers:

for (int ii = 0; ii < blob.numDataBuffers(); ++ii) {
assert(1024 == blob.buffer(ii).size());
}