BDE 4.39.x 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 <span style="color: var(--deprecated-color-dark)">DEPRECATED:</span> 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///
175/// /// Increase the capacity of this stack by at least one element.
176/// void increaseSize();
177///
178/// public:
179/// // CREATORS
180/// my_DoubleStack(bslma::Allocator *basicAllocator = 0);
181/// my_DoubleStack(const my_DoubleStack& original,
182/// bslma::Allocator *basicAllocator = 0);
183/// ~my_DoubleStack();
184///
185/// // MANIPULATORS
186/// my_DoubleStack& operator=(const my_DoubleStack& rhs);
187/// void push(double value);
188/// void pop();
189///
190/// // ACCESSORS
191/// const double& top() const;
192/// bool isEmpty() const;
193/// };
194///
195/// // ...
196///
197/// // MANIPULATORS
198/// inline
199/// void my_DoubleStack::push(double value)
200/// {
201/// if (d_length >= d_size) {
202/// increaseSize();
203/// }
204/// d_stack_p[d_length++] = item;
205/// }
206///
207/// // ...
208/// @endcode
209/// The stack interface takes an optional `basicAllocator` supplied only at
210/// construction. (We avoid use of the name `allocator` so as not to conflict
211/// with the STL use of the word, which differs slightly.) If non-zero, the
212/// stack holds a pointer to this allocator, but does not own it. If no
213/// allocator is supplied, the implementation itself must either conditionally
214/// invoke global `new` and `delete` explicitly whenever dynamic memory must be
215/// managed (BAD IDEA) or (GOOD IDEA) install a default allocator that adapts
216/// use of these global operators to the @ref bslma_allocator interface. In actual
217/// practice, however, we might want the default to be run-time settable from a
218/// central location (see @ref bslma_default ).
219/// @code
220/// // my_doublestack.cpp
221/// // ...
222/// #include <my_doublestack.h>
223/// #include <bslma_allocator.h>
224/// #include <bslma_default.h> // adapter for 'new' and 'delete'
225///
226/// enum { INITIAL_SIZE = 1, GROW_FACTOR = 2 };
227///
228/// // ...
229///
230/// // CREATORS
231/// my_DoubleStack::my_DoubleStack(bslma::Allocator *basicAllocator)
232/// : d_size(INITIAL_SIZE)
233/// , d_length(0)
234/// , d_allocator_p(basicAllocator)
235/// {
236/// assert(d_allocator_p);
237/// d_stack_p = (double *)
238/// d_allocator_p->allocate(d_size * sizeof *d_stack_p);
239/// }
240///
241/// my_DoubleStack::~my_DoubleStack()
242/// {
243/// // CLASS INVARIANTS
244/// assert(d_allocator_p);
245/// assert(d_stack_p);
246/// assert(0 <= d_length);
247/// assert(0 <= d_size);
248/// assert(d_length <= d_size);
249///
250/// d_allocator_p->deallocate(d_stack_p);
251/// }
252/// @endcode
253/// Even in this simplified implementation, all use of the allocator protocol is
254/// relegated to the `.cpp` file. Subsequent use of the allocator is
255/// demonstrated by the following file-scope static reallocation function:
256/// @code
257/// /// Reallocate memory in the specified `array` to have the specified
258/// /// `newSize` using the specified `basicAllocator`. The specified
259/// /// `length` number of leading elements are preserved. Given that the
260/// /// internal policy of class `my_DoubleStack` requires that the physical
261/// /// capacity of the container may grow but never shrink, the behavior is
262/// /// undefined unless `length <= newSize`.
263/// static
264/// void reallocate(double **array, int newSize, int length,
265/// bslma::Allocator *basicAllocator)
266/// {
267/// assert(array);
268/// assert(1 <= newSize);
269/// assert(0 <= length);
270/// assert(basicAllocator);
271/// assert(length <= newSize); // enforce class invariant
272///
273/// double *tmp = *array; // support exception neutrality
274/// *array = (double *) basicAllocator->allocate(newSize * sizeof **array);
275///
276/// // COMMIT POINT
277///
278/// std::memcpy(*array, tmp, length * sizeof **array);
279/// basicAllocator->deallocate(tmp);
280/// }
281///
282/// void my_DoubleStack::increaseSize()
283/// {
284/// int proposedNewSize = d_size * GROW_FACTOR; // reallocate can throw
285/// assert(proposedNewSize > d_length);
286/// reallocate(&d_stack_p, proposedNewSize, d_length, d_allocator_p);
287/// d_size = proposedNewSize; // we're committed
288/// }
289/// @endcode
290/// @}
291/** @} */
292/** @} */
293
294/** @addtogroup bsl
295 * @{
296 */
297/** @addtogroup bslma
298 * @{
299 */
300/** @addtogroup bslma_sequentialallocator
301 * @{
302 */
303
304#ifdef BDE_OPENSOURCE_PUBLICATION // DEPRECATED
305#error "bslma_sequentialallocator is deprecated"
306#endif
307#include <bslscm_version.h>
308
311#include <bslma_sequentialpool.h>
312
313#include <bsls_keyword.h>
314
315
316
317
318namespace bslma {
319
320class Allocator;
321
322 // =========================
323 // class SequentialAllocator
324 // =========================
325
326/// This class implements the `ManagedAllocator` protocol to provide a fast
327/// allocator of arbitrarily-sized blocks of memory. Both the `release`
328/// method and the destructor atomically delete all memory managed by this
329/// allocator; the `deallocate` method, however, has no effect for this
330/// class.
331///
332/// See @ref bslma_sequentialallocator
334
335 // DATA
336 SequentialPool d_sequentialPool; // sequential pool mechanism
337
338 private:
339 // NOT IMPLEMENTED
341 SequentialAllocator& operator=(const SequentialAllocator&);
342
343 public:
344 // CREATORS
345
346 /// Create a sequential allocator for allocating memory blocks from an
347 /// internal buffer. Optionally specify an alignment `strategy` used to
348 /// align allocated memory blocks. If `strategy` is not specified,
349 /// *Natural Alignment* is used. Optionally specify an `initialSize`
350 /// the absolute value of which indicates the initial size (in bytes)
351 /// for the internal buffer. If `initialSize` is not specified, an
352 /// implementation-defined value is used. Optionally specify a
353 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
354 /// the currently installed default allocator is used. If an `allocate`
355 /// or `reserveCapacity` request cannot be satisfied from the current
356 /// buffer, a new buffer is allocated, the size of which is determined
357 /// by a buffer growth strategy implied by `initialSize`. If
358 /// `initialSize` was specified and is negative, or if it was *not*
359 /// specified, the buffer growth strategy used is *Geometric Growth*;
360 /// otherwise it is *Constant Growth*. (See the component level
361 /// documentation for further details.) In either case, the new buffer
362 /// will have sufficient capacity to satisfy the request. If *Geometric
363 /// Growth* is in effect, no limit is imposed on the size of buffers.
364 explicit SequentialAllocator(Allocator *basicAllocator = 0);
365 explicit SequentialAllocator(
367 Allocator *basicAllocator = 0);
368 explicit SequentialAllocator(int initialSize,
369 Allocator *basicAllocator = 0);
371 int initialSize,
373 Allocator *basicAllocator = 0);
374
375 /// Create a sequential allocator for allocating memory blocks initially
376 /// from the specified `buffer` the size (in bytes) of which is
377 /// indicated by the absolute value of the specified `bufferSize`.
378 /// Optionally specify an alignment `strategy` used to align allocated
379 /// memory blocks. If `strategy` is not specified, *Natural Alignment*
380 /// is used. Optionally specify a `basicAllocator` used to supply
381 /// memory. If `basicAllocator` is 0, the currently installed default
382 /// allocator is used. If an `allocate` or `reserveCapacity` request
383 /// cannot be satisfied from the current buffer, a new buffer is
384 /// allocated, the size of which is determined by a buffer growth
385 /// strategy implied by `bufferSize`. If `bufferSize` is negative, the
386 /// buffer growth strategy used is *Geometric Growth*; otherwise it is
387 /// *Constant Growth*. (See the component level documentation for
388 /// further details.) In either case, the new buffer will have
389 /// sufficient capacity to satisfy the request. If *Geometric Growth*
390 /// is in effect, no limit is imposed on the size of buffers.
391 SequentialAllocator(char *buffer,
392 int bufferSize,
393 Allocator *basicAllocator = 0);
395 char *buffer,
396 int bufferSize,
398 Allocator *basicAllocator = 0);
399
400 /// Create a sequential allocator for allocating memory blocks from an
401 /// internal buffer the initial size (in bytes) of which is indicated by
402 /// the absolute value of the specified `initialSize`. The specified
403 /// `maxBufferSize` indicates the maximum size (in bytes) allowed for
404 /// internally allocated buffers. Optionally specify an alignment
405 /// `strategy` used to align allocated memory blocks. If `strategy` is
406 /// not specified, *Natural Alignment* is used. Optionally specify a
407 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
408 /// the currently installed default allocator is used. If an `allocate`
409 /// or `reserveCapacity` request cannot be satisfied from the current
410 /// buffer, a new buffer is allocated, the size of which is determined
411 /// by a buffer growth strategy implied by `initialSize`. If
412 /// `initialSize` is negative, the buffer growth strategy used is
413 /// *Geometric Growth*; otherwise it is *Constant Growth*. (See the
414 /// component level documentation for further details.) In either case,
415 /// the new buffer will have sufficient capacity to satisfy the request.
416 /// If *Geometric Growth* is in effect, the geometric progression of
417 /// buffer sizes is capped at `maxBufferSize`.
418 ///
419 /// \pre The behavior is undefined unless `0 < maxBufferSize`, and `|initialSize| <= maxBufferSize`.
420 ///
421 /// \note Note that `maxBufferSize` is
422 /// ignored if `initialSize > 0`. Also note that `maxBufferSize` may be
423 /// overridden by a sufficiently large value passed to `allocate` or
424 /// `reserveCapacity`.
425 SequentialAllocator(int initialSize,
426 int maxBufferSize,
427 Allocator *basicAllocator = 0);
429 int initialSize,
430 int maxBufferSize,
432 Allocator *basicAllocator = 0);
433
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 `maxBufferSize`.
452 ///
453 /// \pre The behavior is undefined unless
454 /// `0 < maxBufferSize`, and `|bufferSize| <= maxBufferSize`.
455 ///
456 /// \note Note that `maxBufferSize` is ignored if `bufferSize > 0`. Also note that
457 /// `maxBufferSize` may be overridden by a sufficiently large value
458 /// passed to `allocate` or `reserveCapacity`.
459 SequentialAllocator(char *buffer,
460 int bufferSize,
461 int maxBufferSize,
462 Allocator *basicAllocator = 0);
464 char *buffer,
465 int bufferSize,
466 int maxBufferSize,
468 Allocator *basicAllocator = 0);
469
470 /// Destroy this sequential allocator and release all associated memory.
472
473 // MANIPULATORS
474
475 /// Return a newly allocated block of memory of (at least) the specified
476 /// positive `size` (bytes). If `size` is 0, a null pointer is returned with no effect.
477 ///
478 /// \pre The behavior is undefined unless `0 <= size`.
479 ///
480 /// \note Note that the alignment of the address returned is the maximum alignment
481 /// for any fundamental type defined for the calling platform.
483
484 /// Return memory of at least the specified `*size` and return the
485 /// actual amount of memory allocated in `*size`. If `*size` is 0, no
486 /// memory is allocated and 0 is returned.
487 ///
488 /// \pre The behavior is undefined unless `0 <= *size`.
489 void *allocateAndExpand(int *size);
490
491 /// Return memory of at least the specified `*size` and at most the
492 /// specified `maxNumBytes`. Also return the actual amount of memory
493 /// allocated in `*size`. If `*size` is 0, no memory is allocated and 0 is returned.
494 ///
495 /// \pre The behavior is undefined unless
496 /// `0 <= *size <= maxNumBytes`.
497 void *allocateAndExpand(int *size, int maxNumBytes);
498
499 /// This method has no effect for this allocator.
500 void deallocate(void *address) BSLS_KEYWORD_OVERRIDE;
501
502 /// Increase the amount of memory allocated at the specified `address`
503 /// from the specified `originalNumBytes` to the maximum amount easily
504 /// obtainable. Return the amount of memory available at `address` after the expansion.
505 ///
506 /// \pre The behavior is undefined unless the call to
507 /// this allocator that provided the `address` was performed with the `originalNumBytes`.
508 ///
509 /// \note Note that this function will not expand the
510 /// memory unless there have been no allocations since the allocation
511 /// for `originalNumBytes`.
512 int expand(void *address, int originalNumBytes);
513
514 /// Increase the amount of memory allocated at the specified `address`
515 /// from the specified `originalNumBytes` to the maximum amount easily
516 /// obtainable up to the specified `maxNumBytes`. Return the amount of
517 /// memory available at `address` after the expansion.
518 ///
519 /// \pre The behavior is undefined unless the call to this allocator that provided the
520 /// `address` was performed with the `originalNumBytes` and `originalNumBytes < maxNumBytes`.
521 ///
522 /// \note Note that this function will not
523 /// expand the memory unless there have been no allocations since the
524 /// allocation for `originalNumBytes`.
525 int expand(void *address, int originalNumBytes, int maxNumBytes);
526
527 /// Release all memory currently allocated through this allocator.
529
530 /// Reserve sufficient memory to satisfy allocation requests for at
531 /// least the specified `numBytes` without replenishment (i.e., without internal allocation).
532 ///
533 /// \pre The behavior is undefined unless
534 /// `0 <= numBytes`.
535 virtual void reserveCapacity(int numBytes);
536
537 /// Reduce the amount of memory allocated at the specified `address`
538 /// from the specified `originalNumBytes` to the specified
539 /// `newNumBytes`. Return the amount of memory available at `address` after the truncation.
540 ///
541 /// \pre The behavior is undefined unless the call to
542 /// this allocator that provided the `address` was performed with the
543 /// `originalNumBytes` and `newNumBytes <= originalNumBytes`.
544 ///
545 /// \note Note that this function will not truncate the memory unless there have been no
546 /// allocations since the allocation for `originalNumBytes`.
547 int truncate(void *address, int originalNumBytes, int newNumBytes);
548};
549
550// ============================================================================
551// INLINE DEFINITIONS
552// ============================================================================
553
554// CREATORS
555inline
557: d_sequentialPool(basicAllocator)
558{
559}
560
561inline
562SequentialAllocator::SequentialAllocator(
564 Allocator *basicAllocator)
565: d_sequentialPool(strategy, basicAllocator)
566{
567}
568
569inline
570SequentialAllocator::SequentialAllocator(int initialSize,
571 Allocator *basicAllocator)
572: d_sequentialPool(initialSize, basicAllocator)
573{
574}
575
576inline
577SequentialAllocator::SequentialAllocator(
578 int initialSize,
580 Allocator *basicAllocator)
581: d_sequentialPool(initialSize, strategy, basicAllocator)
582{
583}
584
585inline
586SequentialAllocator::SequentialAllocator(char *buffer,
587 int bufferSize,
588 Allocator *basicAllocator)
589: d_sequentialPool(buffer, bufferSize, basicAllocator)
590{
591}
592
593inline
594SequentialAllocator::SequentialAllocator(
595 char *buffer,
596 int bufferSize,
598 Allocator *basicAllocator)
599: d_sequentialPool(buffer, bufferSize, strategy, basicAllocator)
600{
601}
602
603inline
604SequentialAllocator::SequentialAllocator(int initialSize,
605 int maxBufferSize,
606 Allocator *basicAllocator)
607: d_sequentialPool(initialSize, maxBufferSize, basicAllocator)
608{
609}
610
611inline
612SequentialAllocator::SequentialAllocator(
613 int initialSize,
614 int maxBufferSize,
616 Allocator *basicAllocator)
617: d_sequentialPool(initialSize, maxBufferSize, strategy, basicAllocator)
618{
619}
620
621inline
622SequentialAllocator::SequentialAllocator(char *buffer,
623 int bufferSize,
624 int maxBufferSize,
625 Allocator *basicAllocator)
626: d_sequentialPool(buffer, bufferSize, maxBufferSize, basicAllocator)
627{
628}
629
630inline
631SequentialAllocator::SequentialAllocator(
632 char *buffer,
633 int bufferSize,
634 int maxBufferSize,
636 Allocator *basicAllocator)
637: d_sequentialPool(buffer, bufferSize, maxBufferSize, strategy, basicAllocator)
638{
639}
640
641// MANIPULATORS
642inline
644{
645 return d_sequentialPool.allocate(static_cast<int>(numBytes));
646}
647
648inline
650{
651 return d_sequentialPool.allocateAndExpand(size);
652}
653
654inline
655void *SequentialAllocator::allocateAndExpand(int *size, int maxNumBytes)
656{
657 return d_sequentialPool.allocateAndExpand(size, maxNumBytes);
658}
659
660inline
662{
663}
664
665inline
666int SequentialAllocator::expand(void *address, int originalNumBytes)
667{
668 return d_sequentialPool.expand(address, originalNumBytes);
669}
670
671inline
673 int originalNumBytes,
674 int maxNumBytes)
675{
676 return d_sequentialPool.expand(address, originalNumBytes, maxNumBytes);
677}
678
679inline
681{
682 d_sequentialPool.release();
683}
684
685inline
687{
688 d_sequentialPool.reserveCapacity(numBytes);
689}
690
691inline
693 int originalNumBytes,
694 int newNumBytes)
695{
696 return d_sequentialPool.truncate(address, originalNumBytes, newNumBytes);
697}
698
699} // close package namespace
700
701#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
702// ============================================================================
703// BACKWARD COMPATIBILITY
704// ============================================================================
705
706/// This alias is defined for backward compatibility.
708#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
709
710
711
712#endif
713
714// ----------------------------------------------------------------------------
715// Copyright 2013 Bloomberg Finance L.P.
716//
717// Licensed under the Apache License, Version 2.0 (the "License");
718// you may not use this file except in compliance with the License.
719// You may obtain a copy of the License at
720//
721// http://www.apache.org/licenses/LICENSE-2.0
722//
723// Unless required by applicable law or agreed to in writing, software
724// distributed under the License is distributed on an "AS IS" BASIS,
725// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
726// See the License for the specific language governing permissions and
727// limitations under the License.
728// ----------------------------- END-OF-FILE ----------------------------------
729
730/** @} */
731/** @} */
732/** @} */
Definition bslma_allocator.h:545
std::size_t size_type
Definition bslma_allocator.h:593
AlignmentStrategy
Types of alignment strategy to allocate memory.
Definition bslma_bufferallocator.h:274
Definition bslma_managedallocator.h:101
Definition bslma_sequentialallocator.h:333
void * allocate(size_type numBytes) BSLS_KEYWORD_OVERRIDE
Definition bslma_sequentialallocator.h:643
~SequentialAllocator() BSLS_KEYWORD_OVERRIDE
Destroy this sequential allocator and release all associated memory.
int expand(void *address, int originalNumBytes)
Definition bslma_sequentialallocator.h:666
void * allocateAndExpand(int *size)
Definition bslma_sequentialallocator.h:649
void release() BSLS_KEYWORD_OVERRIDE
Release all memory currently allocated through this allocator.
Definition bslma_sequentialallocator.h:680
int truncate(void *address, int originalNumBytes, int newNumBytes)
Definition bslma_sequentialallocator.h:692
void deallocate(void *address) BSLS_KEYWORD_OVERRIDE
This method has no effect for this allocator.
Definition bslma_sequentialallocator.h:661
virtual void reserveCapacity(int numBytes)
Definition bslma_sequentialallocator.h:686
Definition bslma_sequentialpool.h:441
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:707
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition baljsn_encoder_testtypes.h:76