BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma_sequentialallocator.h
Go to the documentation of this file.
1/// @file bslma_sequentialallocator.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslma_sequentialallocator.h -*-C++-*-
8#ifndef INCLUDED_BSLMA_SEQUENTIALALLOCATOR
9#define INCLUDED_BSLMA_SEQUENTIALALLOCATOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslma_sequentialallocator bslma_sequentialallocator
15/// @brief Support fast memory allocation for objects of varying sizes.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslma
19/// @{
20/// @addtogroup bslma_sequentialallocator
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslma_sequentialallocator-purpose"> Purpose</a>
25/// * <a href="#bslma_sequentialallocator-classes"> Classes </a>
26/// * <a href="#bslma_sequentialallocator-description"> Description </a>
27/// * <a href="#bslma_sequentialallocator-alignment-strategy"> Alignment Strategy </a>
28/// * <a href="#bslma_sequentialallocator-optional-buffer-parameter"> Optional buffer Parameter </a>
29/// * <a href="#bslma_sequentialallocator-optional-initialsize-parameter"> Optional initialSize Parameter </a>
30/// * <a href="#bslma_sequentialallocator-internal-buffer-growth"> Internal Buffer Growth </a>
31/// * <a href="#bslma_sequentialallocator-usage"> Usage </a>
32///
33/// # Purpose {#bslma_sequentialallocator-purpose}
34/// Support fast memory allocation for objects of varying sizes.
35///
36/// @deprecated Use @ref bdlma_bufferedsequentialallocator instead.
37///
38/// # Classes {#bslma_sequentialallocator-classes}
39///
40/// - bslma::SequentialAllocator: fast variable-size memory allocator
41///
42/// @see bdlma_sequentialallocator, bdlma_bufferedsequentialallocator
43///
44/// # Description {#bslma_sequentialallocator-description}
45/// This component provides an allocator,
46/// `bslma::SequentialAllocator`, that implements the `bslma::ManagedAllocator`
47/// protocol and allocates memory blocks of any requested size, from an internal
48/// buffer (pool) or a user-supplied buffer. If an allocation request exceeds
49/// the remaining free memory space in the pool, the pool either 1) replenishes
50/// its buffer with new memory to satisfy the request, or 2) returns a separate
51/// memory block, depending on whether the request size exceeds an optionally
52/// specified maximum buffer size. By default, buffer growth is not capped.
53/// The `release` method releases all memory allocated through this allocator,
54/// as does the destructor. Note, however, that individual allocated blocks of
55/// memory cannot be separately deallocated.
56/// @code
57/// ,--------------------------.
58/// ( bslma::SequentialAllocator )
59/// `--------------------------'
60/// | ctor/dtor
61/// | allocateAndExpand
62/// | expand
63/// | reserveCapacity
64/// | truncate
65/// V
66/// ,-----------------------.
67/// ( bslma::ManagedAllocator )
68/// `-----------------------'
69/// | release
70/// V
71/// ,-----------------.
72/// ( bslma::Allocator )
73/// `-----------------'
74/// allocate
75/// deallocate
76/// @endcode
77///
78/// ## Alignment Strategy {#bslma_sequentialallocator-alignment-strategy}
79///
80///
81/// The `bslma::SequentialPool` allocates memory using one of the two alignment
82/// strategies (defined in @ref bslma_bufferallocator ) optionally specified at
83/// construction: 1) MAXIMUM ALIGNMENT or 2) NATURAL ALIGNMENT.
84///
85/// 1. MAXIMUM ALIGNMENT: This strategy always allocates memory aligned with the
86/// most restrictive alignment on the host platform. The value is defined by
87/// `bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT`.
88/// 2. NATURAL ALIGNMENT: This strategy allocates memory whose alignment depends
89/// on the requested number of bytes. An object of a fundamental type
90/// (`int`, etc.) is *naturally* *aligned* when it's size evenly divides its
91/// address. An object of an aggregate type has natural alignment if the
92/// alignment of the most-restrictively aligned sub-object evenly divides the
93/// address of the aggregate. Natural alignment is always at least as
94/// restrictive as the compiler's required alignment. When only the size of
95/// an aggregate is known, and not its composition, we compute the alignment
96/// by finding the largest integral power of 2 (up to and including
97/// `bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT`) that divides the requested
98/// (non-zero) number of bytes. This computed alignment is guaranteed to be
99/// at least as restrictive as any sub-object within the aggregate.
100///
101/// The default strategy is NATURAL ALIGNMENT.
102///
103/// ## Optional buffer Parameter {#bslma_sequentialallocator-optional-buffer-parameter}
104///
105///
106/// A buffer can be supplied to a `bslma::SequentialAllocator` object at
107/// construction in which case the allocator will try to satisfy allocation
108/// requests using this buffer before switching to a dynamically-allocated
109/// internal pool. Once the allocator is using an internal pool, it will not
110/// try to satisfy any subsequent allocation requests from the supplied buffer.
111/// Note that the allocator does *not* take ownership of the buffer. Also note
112/// that `bufferSize` may be specified using a positive or negative value to
113/// indicate a buffer growth strategy (see "Internal Buffer Growth").
114///
115/// ## Optional initialSize Parameter {#bslma_sequentialallocator-optional-initialsize-parameter}
116///
117///
118/// In lieu of an externally-supplied buffer, a value for the `initialSize`
119/// parameter may be supplied at construction to specify the initial size of the
120/// internal pool. If neither a buffer nor an `initialSize` is specified, an
121/// implementation-defined value is used for an initial size of the internal
122/// pool. Note that `initialSize` may be specified using a positive or negative
123/// value to indicate a buffer growth strategy (see "Internal Buffer Growth").
124///
125/// ## Internal Buffer Growth {#bslma_sequentialallocator-internal-buffer-growth}
126///
127///
128/// A `bslma::SequentialAllocator` replenishes its internal buffer if the
129/// current buffer cannot satisfy an allocation request. It does so by one of
130/// two growth strategies:
131///
132/// Constant Growth: The new buffer is always of the same size as the current
133/// buffer (possibly supplied at construction).
134///
135/// Geometric Growth: The new buffer will be geometrically larger than the
136/// current buffer up to an optionally-specified maximum limit.
137///
138/// If a `bufferSize` (and corresponding `buffer`) or `initialSize` is supplied
139/// at construction, the sign of its value implicitly specifies which growth
140/// strategy to use. A positive value indicates Constant Growth, whereas a a
141/// negative value indicates Geometric Growth. If neither `bufferSize` nor
142/// `initialSize` is supplied, Geometric Growth is used. The optional
143/// `maxBufferSize` parameter may be used to place a cap on Geometric Growth
144/// (`maxBufferSize` is ignored if Constant Growth is in effect). If no value
145/// is specified for `maxBufferSize`, there is no cap on Geometric Growth. Note
146/// that `reserveCapacity` always ensures that the requested number of bytes is
147/// available (allocating a new internal pool if necessary) irrespective of
148/// whether the size of the request exceeds `maxBufferSize`.
149///
150/// ## Usage {#bslma_sequentialallocator-usage}
151///
152///
153/// Allocators are often supplied to objects requiring dynamically-allocated
154/// memory at construction. For example, consider the following
155/// `my_DoubleStack` class, parameterized by a `bslma::Allocator`:
156/// @code
157/// // my_doublestack.h
158/// // ...
159///
160/// namespace bslma { class Allocator; }
161///
162/// class my_DoubleStack {
163/// // DATA
164/// double *d_stack_p; // dynamically-allocated array
165/// int d_size; // physical capacity this stack
166/// int d_length; // next available index in stack
167/// bslma::Allocator *d_allocator_p; // memory allocator (held, not owned)
168///
169/// // FRIENDS
170/// friend class my_DoubleStackIter;
171///
172/// private:
173/// // PRIVATE MANIPULATORS
174/// void increaseSize();
175/// // Increase the capacity of this stack by at least one element.
176///
177/// public:
178/// // CREATORS
179/// my_DoubleStack(bslma::Allocator *basicAllocator = 0);
180/// my_DoubleStack(const my_DoubleStack& original,
181/// bslma::Allocator *basicAllocator = 0);
182/// ~my_DoubleStack();
183///
184/// // MANIPULATORS
185/// my_DoubleStack& operator=(const my_DoubleStack& rhs);
186/// void push(double value);
187/// void pop();
188///
189/// // ACCESSORS
190/// const double& top() const;
191/// bool isEmpty() const;
192/// };
193///
194/// // ...
195///
196/// // MANIPULATORS
197/// inline
198/// void my_DoubleStack::push(double value)
199/// {
200/// if (d_length >= d_size) {
201/// increaseSize();
202/// }
203/// d_stack_p[d_length++] = item;
204/// }
205///
206/// // ...
207/// @endcode
208/// The stack interface takes an optional `basicAllocator` supplied only at
209/// construction. (We avoid use of the name `allocator` so as not to conflict
210/// with the STL use of the word, which differs slightly.) If non-zero, the
211/// stack holds a pointer to this allocator, but does not own it. If no
212/// allocator is supplied, the implementation itself must either conditionally
213/// invoke global `new` and `delete` explicitly whenever dynamic memory must be
214/// managed (BAD IDEA) or (GOOD IDEA) install a default allocator that adapts
215/// use of these global operators to the @ref bslma_allocator interface. In actual
216/// practice, however, we might want the default to be run-time settable from a
217/// central location (see @ref bslma_default ).
218/// @code
219/// // my_doublestack.cpp
220/// // ...
221/// #include <my_doublestack.h>
222/// #include <bslma_allocator.h>
223/// #include <bslma_default.h> // adapter for 'new' and 'delete'
224///
225/// enum { INITIAL_SIZE = 1, GROW_FACTOR = 2 };
226///
227/// // ...
228///
229/// // CREATORS
230/// my_DoubleStack::my_DoubleStack(bslma::Allocator *basicAllocator)
231/// : d_size(INITIAL_SIZE)
232/// , d_length(0)
233/// , d_allocator_p(basicAllocator)
234/// {
235/// assert(d_allocator_p);
236/// d_stack_p = (double *)
237/// d_allocator_p->allocate(d_size * sizeof *d_stack_p);
238/// }
239///
240/// my_DoubleStack::~my_DoubleStack()
241/// {
242/// // CLASS INVARIANTS
243/// assert(d_allocator_p);
244/// assert(d_stack_p);
245/// assert(0 <= d_length);
246/// assert(0 <= d_size);
247/// assert(d_length <= d_size);
248///
249/// d_allocator_p->deallocate(d_stack_p);
250/// }
251/// @endcode
252/// Even in this simplified implementation, all use of the allocator protocol is
253/// relegated to the `.cpp` file. Subsequent use of the allocator is
254/// demonstrated by the following file-scope static reallocation function:
255/// @code
256/// static
257/// void reallocate(double **array, int newSize, int length,
258/// bslma::Allocator *basicAllocator)
259/// // Reallocate memory in the specified 'array' to have the specified
260/// // 'newSize' using the specified 'basicAllocator'. The specified
261/// // 'length' number of leading elements are preserved. Given that the
262/// // internal policy of class 'my_DoubleStack' requires that the physical
263/// // capacity of the container may grow but never shrink, the behavior is
264/// // undefined unless length <= newSize.
265/// {
266/// assert(array);
267/// assert(1 <= newSize);
268/// assert(0 <= length);
269/// assert(basicAllocator);
270/// assert(length <= newSize); // enforce class invariant
271///
272/// double *tmp = *array; // support exception neutrality
273/// *array = (double *) basicAllocator->allocate(newSize * sizeof **array);
274///
275/// // COMMIT POINT
276///
277/// std::memcpy(*array, tmp, length * sizeof **array);
278/// basicAllocator->deallocate(tmp);
279/// }
280///
281/// void my_DoubleStack::increaseSize()
282/// {
283/// int proposedNewSize = d_size * GROW_FACTOR; // reallocate can throw
284/// assert(proposedNewSize > d_length);
285/// reallocate(&d_stack_p, proposedNewSize, d_length, d_allocator_p);
286/// d_size = proposedNewSize; // we're committed
287/// }
288/// @endcode
289/// @}
290/** @} */
291/** @} */
292
293/** @addtogroup bsl
294 * @{
295 */
296/** @addtogroup bslma
297 * @{
298 */
299/** @addtogroup bslma_sequentialallocator
300 * @{
301 */
302
303#ifdef BDE_OPENSOURCE_PUBLICATION // DEPRECATED
304#error "bslma_sequentialallocator is deprecated"
305#endif
306#include <bslscm_version.h>
307
310#include <bslma_sequentialpool.h>
311
312#include <bsls_keyword.h>
313
314
315
316
317namespace bslma {
318
319class Allocator;
320
321 // =========================
322 // class SequentialAllocator
323 // =========================
324
325/// This class implements the `ManagedAllocator` protocol to provide a fast
326/// allocator of arbitrarily-sized blocks of memory. Both the `release`
327/// method and the destructor atomically delete all memory managed by this
328/// allocator; the `deallocate` method, however, has no effect for this
329/// class.
330///
331/// See @ref bslma_sequentialallocator
333
334 // DATA
335 SequentialPool d_sequentialPool; // sequential pool mechanism
336
337 // NOT IMPLEMENTED
339 SequentialAllocator& operator=(const SequentialAllocator&);
340
341 public:
342 // CREATORS
343
344 explicit SequentialAllocator(Allocator *basicAllocator = 0);
345 explicit SequentialAllocator(
347 Allocator *basicAllocator = 0);
348 explicit SequentialAllocator(int initialSize,
349 Allocator *basicAllocator = 0);
350 /// Create a sequential allocator for allocating memory blocks from an
351 /// internal buffer. Optionally specify an alignment `strategy` used to
352 /// align allocated memory blocks. If `strategy` is not specified,
353 /// *Natural Alignment* is used. Optionally specify an `initialSize`
354 /// the absolute value of which indicates the initial size (in bytes)
355 /// for the internal buffer. If `initialSize` is not specified, an
356 /// implementation-defined value is used. Optionally specify a
357 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
358 /// the currently installed default allocator is used. If an `allocate`
359 /// or `reserveCapacity` request cannot be satisfied from the current
360 /// buffer, a new buffer is allocated, the size of which is determined
361 /// by a buffer growth strategy implied by `initialSize`. If
362 /// `initialSize` was specified and is negative, or if it was *not*
363 /// specified, the buffer growth strategy used is *Geometric Growth*;
364 /// otherwise it is *Constant Growth*. (See the component level
365 /// documentation for further details.) In either case, the new buffer
366 /// will have sufficient capacity to satisfy the request. If *Geometric
367 /// Growth* is in effect, no limit is imposed on the size of buffers.
369 int initialSize,
371 Allocator *basicAllocator = 0);
372
373 SequentialAllocator(char *buffer,
374 int bufferSize,
375 Allocator *basicAllocator = 0);
376 /// Create a sequential allocator for allocating memory blocks initially
377 /// from the specified `buffer` the size (in bytes) of which is
378 /// indicated by the absolute value of the specified `bufferSize`.
379 /// Optionally specify an alignment `strategy` used to align allocated
380 /// memory blocks. If `strategy` is not specified, *Natural Alignment*
381 /// is used. Optionally specify a `basicAllocator` used to supply
382 /// memory. If `basicAllocator` is 0, the currently installed default
383 /// allocator is used. If an `allocate` or `reserveCapacity` request
384 /// cannot be satisfied from the current buffer, a new buffer is
385 /// allocated, the size of which is determined by a buffer growth
386 /// strategy implied by `bufferSize`. If `bufferSize` is negative, the
387 /// buffer growth strategy used is *Geometric Growth*; otherwise it is
388 /// *Constant Growth*. (See the component level documentation for
389 /// further details.) In either case, the new buffer will have
390 /// sufficient capacity to satisfy the request. If *Geometric Growth*
391 /// is in effect, no limit is imposed on the size of buffers.
393 char *buffer,
394 int bufferSize,
396 Allocator *basicAllocator = 0);
397
398 SequentialAllocator(int initialSize,
399 int maxBufferSize,
400 Allocator *basicAllocator = 0);
401 /// Create a sequential allocator for allocating memory blocks from an
402 /// internal buffer the initial size (in bytes) of which is indicated by
403 /// the absolute value of the specified `initialSize`. The specified
404 /// `maxBufferSize` indicates the maximum size (in bytes) allowed for
405 /// internally allocated buffers. Optionally specify an alignment
406 /// `strategy` used to align allocated memory blocks. If `strategy` is
407 /// not specified, *Natural Alignment* is used. Optionally specify a
408 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
409 /// the currently installed default allocator is used. If an `allocate`
410 /// or `reserveCapacity` request cannot be satisfied from the current
411 /// buffer, a new buffer is allocated, the size of which is determined
412 /// by a buffer growth strategy implied by `initialSize`. If
413 /// `initialSize` is negative, the buffer growth strategy used is
414 /// *Geometric Growth*; otherwise it is *Constant Growth*. (See the
415 /// component level documentation for further details.) In either case,
416 /// the new buffer will have sufficient capacity to satisfy the request.
417 /// If *Geometric Growth* is in effect, the geometric progression of
418 /// buffer sizes is capped at `maxBufferSize`. The behavior is
419 /// undefined unless `0 < maxBufferSize`, and
420 /// `|initialSize| <= maxBufferSize`. Note that `maxBufferSize` is
421 /// ignored if `initialSize > 0`. Also note that `maxBufferSize` may be
422 /// overridden by a sufficiently large value passed to `allocate` or
423 /// `reserveCapacity`.
425 int initialSize,
426 int maxBufferSize,
428 Allocator *basicAllocator = 0);
429
430 SequentialAllocator(char *buffer,
431 int bufferSize,
432 int maxBufferSize,
433 Allocator *basicAllocator = 0);
434 /// Create a sequential allocator for allocating memory blocks initially
435 /// from the specified `buffer` the size (in bytes) of which is
436 /// indicated by the absolute value of the specified `bufferSize`. The
437 /// specified `maxBufferSize` indicates the maximum size (in bytes)
438 /// allowed for internally allocated buffers. Optionally specify an
439 /// alignment `strategy` used to align allocated memory blocks. If
440 /// `strategy` is not specified, *Natural Alignment* is used.
441 /// Optionally specify a `basicAllocator` used to supply memory. If
442 /// `basicAllocator` is 0, the currently installed default allocator is
443 /// used. If an `allocate` or `reserveCapacity` request cannot be
444 /// satisfied from the current buffer, a new buffer is allocated, the
445 /// size of which is determined by a buffer growth strategy implied by
446 /// `bufferSize`. If `bufferSize` is negative, the buffer growth
447 /// strategy used is *Geometric Growth*; otherwise it is *Constant
448 /// Growth*. (See the component level documentation for further
449 /// details.) In either case, the new buffer will have sufficient
450 /// capacity to satisfy the request. If *Geometric Growth* is in
451 /// effect, the geometric progression of buffer sizes is capped at
452 /// `maxBufferSize`. The behavior is undefined unless
453 /// `0 < maxBufferSize`, and `|bufferSize| <= maxBufferSize`. Note that
454 /// `maxBufferSize` is ignored if `bufferSize > 0`. Also note that
455 /// `maxBufferSize` may be overridden by a sufficiently large value
456 /// passed to `allocate` or `reserveCapacity`.
458 char *buffer,
459 int bufferSize,
460 int maxBufferSize,
462 Allocator *basicAllocator = 0);
463
464 /// Destroy this sequential allocator and release all associated memory.
466
467 // MANIPULATORS
468
469 /// Return a newly allocated block of memory of (at least) the specified
470 /// positive `size` (bytes). If `size` is 0, a null pointer is returned
471 /// with no effect. The behavior is undefined unless `0 <= size`. Note
472 /// that the alignment of the address returned is the maximum alignment
473 /// for any fundamental type defined for the calling platform.
475
476 /// Return memory of at least the specified `*size` and return the
477 /// actual amount of memory allocated in `*size`. If `*size` is 0, no
478 /// memory is allocated and 0 is returned. The behavior is undefined
479 /// unless `0 <= *size`.
480 void *allocateAndExpand(int *size);
481
482 /// Return memory of at least the specified `*size` and at most the
483 /// specified `maxNumBytes`. Also return the actual amount of memory
484 /// allocated in `*size`. If `*size` is 0, no memory is allocated and 0
485 /// is returned. The behavior is undefined unless
486 /// `0 <= *size <= maxNumBytes`.
487 void *allocateAndExpand(int *size, int maxNumBytes);
488
489 /// This method has no effect for this allocator.
490 void deallocate(void *address) BSLS_KEYWORD_OVERRIDE;
491
492 /// Increase the amount of memory allocated at the specified `address`
493 /// from the specified `originalNumBytes` to the maximum amount easily
494 /// obtainable. Return the amount of memory available at `address`
495 /// after the expansion. The behavior is undefined unless the call to
496 /// this allocator that provided the `address` was performed with the
497 /// `originalNumBytes`. Note that this function will not expand the
498 /// memory unless there have been no allocations since the allocation
499 /// for `originalNumBytes`.
500 int expand(void *address, int originalNumBytes);
501
502 /// Increase the amount of memory allocated at the specified `address`
503 /// from the specified `originalNumBytes` to the maximum amount easily
504 /// obtainable up to the specified `maxNumBytes`. Return the amount of
505 /// memory available at `address` after the expansion. The behavior is
506 /// undefined unless the call to this allocator that provided the
507 /// `address` was performed with the `originalNumBytes` and
508 /// `originalNumBytes < maxNumBytes`. Note that this function will not
509 /// expand the memory unless there have been no allocations since the
510 /// allocation for `originalNumBytes`.
511 int expand(void *address, int originalNumBytes, int maxNumBytes);
512
513 /// Release all memory currently allocated through this allocator.
515
516 /// Reserve sufficient memory to satisfy allocation requests for at
517 /// least the specified `numBytes` without replenishment (i.e., without
518 /// internal allocation). The behavior is undefined unless
519 /// `0 <= numBytes`.
520 virtual void reserveCapacity(int numBytes);
521
522 /// Reduce the amount of memory allocated at the specified `address`
523 /// from the specified `originalNumBytes` to the specified
524 /// `newNumBytes`. Return the amount of memory available at `address`
525 /// after the truncation. The behavior is undefined unless the call to
526 /// this allocator that provided the `address` was performed with the
527 /// `originalNumBytes` and `newNumBytes <= originalNumBytes`. Note that
528 /// this function will not truncate the memory unless there have been no
529 /// allocations since the allocation for `originalNumBytes`.
530 int truncate(void *address, int originalNumBytes, int newNumBytes);
531};
532
533// ============================================================================
534// INLINE DEFINITIONS
535// ============================================================================
536
537// CREATORS
538inline
540: d_sequentialPool(basicAllocator)
541{
542}
543
544inline
545SequentialAllocator::SequentialAllocator(
547 Allocator *basicAllocator)
548: d_sequentialPool(strategy, basicAllocator)
549{
550}
551
552inline
553SequentialAllocator::SequentialAllocator(int initialSize,
554 Allocator *basicAllocator)
555: d_sequentialPool(initialSize, basicAllocator)
556{
557}
558
559inline
560SequentialAllocator::SequentialAllocator(
561 int initialSize,
563 Allocator *basicAllocator)
564: d_sequentialPool(initialSize, strategy, basicAllocator)
565{
566}
567
568inline
569SequentialAllocator::SequentialAllocator(char *buffer,
570 int bufferSize,
571 Allocator *basicAllocator)
572: d_sequentialPool(buffer, bufferSize, basicAllocator)
573{
574}
575
576inline
577SequentialAllocator::SequentialAllocator(
578 char *buffer,
579 int bufferSize,
581 Allocator *basicAllocator)
582: d_sequentialPool(buffer, bufferSize, strategy, basicAllocator)
583{
584}
585
586inline
587SequentialAllocator::SequentialAllocator(int initialSize,
588 int maxBufferSize,
589 Allocator *basicAllocator)
590: d_sequentialPool(initialSize, maxBufferSize, basicAllocator)
591{
592}
593
594inline
595SequentialAllocator::SequentialAllocator(
596 int initialSize,
597 int maxBufferSize,
599 Allocator *basicAllocator)
600: d_sequentialPool(initialSize, maxBufferSize, strategy, basicAllocator)
601{
602}
603
604inline
605SequentialAllocator::SequentialAllocator(char *buffer,
606 int bufferSize,
607 int maxBufferSize,
608 Allocator *basicAllocator)
609: d_sequentialPool(buffer, bufferSize, maxBufferSize, basicAllocator)
610{
611}
612
613inline
614SequentialAllocator::SequentialAllocator(
615 char *buffer,
616 int bufferSize,
617 int maxBufferSize,
619 Allocator *basicAllocator)
620: d_sequentialPool(buffer, bufferSize, maxBufferSize, strategy, basicAllocator)
621{
622}
623
624// MANIPULATORS
625inline
627{
628 return d_sequentialPool.allocate(static_cast<int>(numBytes));
629}
630
631inline
633{
634 return d_sequentialPool.allocateAndExpand(size);
635}
636
637inline
638void *SequentialAllocator::allocateAndExpand(int *size, int maxNumBytes)
639{
640 return d_sequentialPool.allocateAndExpand(size, maxNumBytes);
641}
642
643inline
645{
646}
647
648inline
649int SequentialAllocator::expand(void *address, int originalNumBytes)
650{
651 return d_sequentialPool.expand(address, originalNumBytes);
652}
653
654inline
656 int originalNumBytes,
657 int maxNumBytes)
658{
659 return d_sequentialPool.expand(address, originalNumBytes, maxNumBytes);
660}
661
662inline
664{
665 d_sequentialPool.release();
666}
667
668inline
670{
671 d_sequentialPool.reserveCapacity(numBytes);
672}
673
674inline
676 int originalNumBytes,
677 int newNumBytes)
678{
679 return d_sequentialPool.truncate(address, originalNumBytes, newNumBytes);
680}
681
682} // close package namespace
683
684#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
685// ============================================================================
686// BACKWARD COMPATIBILITY
687// ============================================================================
688
689/// This alias is defined for backward compatibility.
691#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
692
693
694
695#endif
696
697// ----------------------------------------------------------------------------
698// Copyright 2013 Bloomberg Finance L.P.
699//
700// Licensed under the Apache License, Version 2.0 (the "License");
701// you may not use this file except in compliance with the License.
702// You may obtain a copy of the License at
703//
704// http://www.apache.org/licenses/LICENSE-2.0
705//
706// Unless required by applicable law or agreed to in writing, software
707// distributed under the License is distributed on an "AS IS" BASIS,
708// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
709// See the License for the specific language governing permissions and
710// limitations under the License.
711// ----------------------------- END-OF-FILE ----------------------------------
712
713/** @} */
714/** @} */
715/** @} */
Definition bslma_allocator.h:457
std::size_t size_type
Definition bslma_allocator.h:499
AlignmentStrategy
Types of alignment strategy to allocate memory.
Definition bslma_bufferallocator.h:274
Definition bslma_managedallocator.h:101
Definition bslma_sequentialallocator.h:332
void * allocate(size_type numBytes) BSLS_KEYWORD_OVERRIDE
Definition bslma_sequentialallocator.h:626
~SequentialAllocator() BSLS_KEYWORD_OVERRIDE
Destroy this sequential allocator and release all associated memory.
int expand(void *address, int originalNumBytes)
Definition bslma_sequentialallocator.h:649
void * allocateAndExpand(int *size)
Definition bslma_sequentialallocator.h:632
void release() BSLS_KEYWORD_OVERRIDE
Release all memory currently allocated through this allocator.
Definition bslma_sequentialallocator.h:663
int truncate(void *address, int originalNumBytes, int newNumBytes)
Definition bslma_sequentialallocator.h:675
void deallocate(void *address) BSLS_KEYWORD_OVERRIDE
This method has no effect for this allocator.
Definition bslma_sequentialallocator.h:644
virtual void reserveCapacity(int numBytes)
Definition bslma_sequentialallocator.h:669
Definition bslma_sequentialpool.h:440
void reserveCapacity(int numBytes)
int truncate(void *address, int originalNumBytes, int newNumBytes)
int expand(void *address, int originalNumBytes)
void * allocateAndExpand(int *size)
void * allocate(int size)
void release()
Release all memory currently allocated through this pool.
bslma::SequentialAllocator bslma_SequentialAllocator
This alias is defined for backward compatibility.
Definition bslma_sequentialallocator.h:690
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition balxml_encoderoptions.h:68