[#BloombergLP-bslma-Default] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::Default :relfileprefix: ../../ :mrdocs: 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. == Synopsis Declared in `<bslma_default.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Default; ---- == Description 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. == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/Default/allocator.adoc[`allocator`] | 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. | xref:BloombergLP/bslma/Default/defaultAllocator.adoc[`defaultAllocator`] | 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. | xref:BloombergLP/bslma/Default/globalAllocator.adoc[`globalAllocator`] | 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. | xref:BloombergLP/bslma/Default/lockDefaultAllocator.adoc[`lockDefaultAllocator`] | 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. | xref:BloombergLP/bslma/Default/setDefaultAllocator.adoc[`setDefaultAllocator`] | 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. | xref:BloombergLP/bslma/Default/setDefaultAllocatorRaw.adoc[`setDefaultAllocatorRaw`] | 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. | xref:BloombergLP/bslma/Default/setGlobalAllocator.adoc[`setGlobalAllocator`] | 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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#