[#BloombergLP-bslma-Allocator-allocate-04]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::xref:BloombergLP/bslma/Allocator.adoc[Allocator]::allocate
:relfileprefix: ../../../
:mrdocs:

Return a newly allocated block of memory of at least `size` bytes&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
virtual
void*
allocate(xref:BloombergLP/bslma/Allocator/size_type.adoc[size&lowbar;type] size) = 0;
----

== Description

Return a newly allocated block of memory of (at least) the specified positive `size` (in bytes)&period; If `size` is 0, a null pointer is returned with no other effect&period; If this allocator cannot return the requested number of bytes, then it will throw a `std&colon;&colon;bad&lowbar;alloc` exception in an exception&hyphen;enabled build, or else will abort the program in a non&hyphen;exception build&period; The behavior is undefined unless `0 &lt;&equals; size`&period; Note that the alignment of the address returned conforms to the platform requirement for any object of the specified `size`&period; Note that this virtual function hides a two&hyphen;parameter non&hyphen;virtual `allocate` method inherited from `bsl&colon;&colon;memory&lowbar;resource`&semi; to access the inherited function, upcast the object to `bsl&colon;&colon;memory&lowbar;resource&amp;` before calling the base&hyphen;class function&period;

== Return Value

pointer to the allocated memory, or null if `size` is 0

== Parameters

[cols="1,4"]
|===
| Name| Description
| *size*
| number of bytes to allocate
|===


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