[#BloombergLP-bslma-Default]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::Default
:relfileprefix: ../../
:mrdocs:

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

== Synopsis

Declared in `&lt;bslma&lowbar;default&period;h&gt;`

[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`)&period; The global allocator may be freely modified&period;

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&period;

== 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&hyphen;specified `basicAllocator` is 0&semi; return `basicAllocator` otherwise&period;
| xref:BloombergLP/bslma/Default/defaultAllocator.adoc[`defaultAllocator`] 
| Return the address of the default allocator and disable all subsequent calls to the `setDefaultAllocator` method&period; Note that prior to the first call to `setDefaultAllocator` or `setDefaultAllocatorRaw` methods, the address of the default allocator is that of the `NewDeleteAllocator` singleton&period; Also note that subsequent calls to `setDefaultAllocatorRaw` method are _not_ disabled by this method&period;
| xref:BloombergLP/bslma/Default/globalAllocator.adoc[`globalAllocator`] 
| Return the address of the global allocator if the optionally&hyphen; specified `basicAllocator` is 0, and `basicAllocator` otherwise&period; Note that prior to the first call to the `setGlobalAllocator` method, the address of the global allocator is that of the `NewDeleteAllocator` singleton&period;
| xref:BloombergLP/bslma/Default/lockDefaultAllocator.adoc[`lockDefaultAllocator`] 
| Disable all subsequent calls to the `setDefaultAllocator` method&period; Subsequent calls to this method have no effect&period; Note that subsequent calls to the `setDefaultAllocatorRaw` method are _not_ disabled by this method&period;
| 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&period; Return 0 on success and a non&hyphen;zero value otherwise&period; This method will fail if either `defaultAllocator`, `lockDefaultAllocator`, or `allocator` with argument 0 has been called previously in this process&period; In C&plus;&plus;17 and later, a successful call to this method will also set the default `std&colon;&colon;pmr&colon;&colon;memory&lowbar;resource`&period; 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&period; 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&period;
| xref:BloombergLP/bslma/Default/setDefaultAllocatorRaw.adoc[`setDefaultAllocatorRaw`] 
| Unconditionally set the address of the default allocator to the specified `basicAllocator`&period; In C&plus;&plus;17 and later, a call to this method will also set the default `std&colon;&colon;pmr&colon;&colon;memory&lowbar;resource`&period; 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&period; 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&period;
| 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&period; Return the address of the global allocator in effect immediately before calling this method&period; 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&period; Note that prior to the first call to this method, the address of the global allocator is that of the `NewDeleteAllocator` singleton&period; 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&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
