Quick Links:

bal | bbl | bdl | bsl

Static Public Member Functions

bslma::Default Struct Reference

#include <bslma_default.h>

List of all members.

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.

See Component bslma_default


Member Function Documentation

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. 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.

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

Unconditionally set the address of the default allocator to the specified basicAllocator. 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.

static void bslma::Default::lockDefaultAllocator (  )  [static]

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.

static Allocator* bslma::Default::defaultAllocator (  )  [static]

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.

static Allocator* bslma::Default::allocator ( Allocator basicAllocator = 0  )  [static]

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.

static Allocator* bslma::Default::globalAllocator ( Allocator basicAllocator = 0  )  [static]

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.

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: