BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma::Default Struct Reference

#include <bslma_default.h>

Static Public Member Functions

static int setDefaultAllocator (Allocator *basicAllocator)
 
static void setDefaultAllocatorRaw (Allocator *basicAllocator)
 
static void lockDefaultAllocator ()
 
static AllocatordefaultAllocator ()
 
static Allocatorallocator (Allocator *basicAllocator=0)
 
static AllocatorglobalAllocator (Allocator *basicAllocator=0)
 
static AllocatorsetGlobalAllocator (Allocator *basicAllocator)
 

Detailed Description

This struct is a mechanism with global state, i.e., all state is held in global variables and all functions are class methods. The state consists of two distinct parts that don't influence one another: the default allocator and the global allocator. All addresses are stored without assuming ownership.

The setDefaultAllocator method will only modify the default allocator prior to the default allocator being accessed (by either allocator, defaultAllocator, or lockDefaultAllocator). The global allocator may be freely modified.

Note that only the owner of main (or in testing), where the caller affirmatively takes responsibility for the behavior of all clients of the global allocator, is intended to change the global allocator.

Member Function Documentation

◆ allocator()

Allocator * bslma::Default::allocator ( Allocator basicAllocator = 0)
inlinestatic

Return the allocator returned by defaultAllocator and disable all subsequent calls to the setDefaultAllocator method if the optionally-specified basicAllocator is 0; return basicAllocator otherwise.

◆ defaultAllocator()

Allocator * bslma::Default::defaultAllocator ( )
inlinestatic

Return the address of the default allocator and disable all subsequent calls to the setDefaultAllocator method. Note that prior to the first call to setDefaultAllocator or setDefaultAllocatorRaw methods, the address of the default allocator is that of the NewDeleteAllocator singleton. Also note that subsequent calls to setDefaultAllocatorRaw method are not disabled by this method.

◆ globalAllocator()

Allocator * bslma::Default::globalAllocator ( Allocator basicAllocator = 0)
inlinestatic

Return the address of the global allocator if the optionally- specified basicAllocator is 0, and basicAllocator otherwise. Note that prior to the first call to the setGlobalAllocator method, the address of the global allocator is that of the NewDeleteAllocator singleton.

◆ lockDefaultAllocator()

void bslma::Default::lockDefaultAllocator ( )
inlinestatic

Disable all subsequent calls to the setDefaultAllocator method. Subsequent calls to this method have no effect. Note that subsequent calls to the setDefaultAllocatorRaw method are not disabled by this method.

◆ setDefaultAllocator()

static int bslma::Default::setDefaultAllocator ( Allocator basicAllocator)
static

Set the address of the default allocator to the specified basicAllocator unless calls to this method have been disabled. Return 0 on success and a non-zero value otherwise. This method will fail if either defaultAllocator, lockDefaultAllocator, or allocator with argument 0 has been called previously in this process. In C++17 and later, a successful call to this method will also set the default std::pmr::memory_resource. The behavior is undefined unless basicAllocator is the address of an allocator with sufficient lifetime to satisfy all allocation requests within this process, and unless there is only one thread started within this process. Note that this method is intended for use only by the owner of main (or for use in testing) where the caller affirmatively takes responsibility for the behavior of all clients of the default allocator, and should not be used for any other purpose.

◆ setDefaultAllocatorRaw()

static void bslma::Default::setDefaultAllocatorRaw ( Allocator basicAllocator)
static

Unconditionally set the address of the default allocator to the specified basicAllocator. In C++17 and later, a call to this method will also set the default std::pmr::memory_resource. The behavior is undefined unless basicAllocator is the address of an allocator with sufficient lifetime to satisfy all allocation requests within this process, and unless there is only one thread started within this process. Note that this method is intended for use only in testing where the caller affirmatively takes responsibility for the behavior of all clients of the default allocator, and should not be used for any other purpose.

◆ setGlobalAllocator()

static Allocator * bslma::Default::setGlobalAllocator ( Allocator basicAllocator)
static

Unconditionally set the address of the global allocator to the specified basicAllocator, or to the address of the NewDeleteAllocator singleton if basicAllocator is 0. Return the address of the global allocator in effect immediately before calling this method. The behavior is undefined unless basicAllocator is 0 or is the address of an allocator with sufficient lifetime to satisfy all global allocation requests within this process, and unless there is only one thread started within this process. Note that prior to the first call to this method, the address of the global allocator is that of the NewDeleteAllocator singleton. Also note that this method is intended for use only by the owner of main (or for use in testing) where the caller affirmatively takes responsibility for the behavior of all clients of the global allocator, and should not be used for any other purpose.


The documentation for this struct was generated from the following file: