Blaze 3.9
Loading...
Searching...
No Matches
Memory.h File Reference

Header file for memory allocation and deallocation functionality. More...

Go to the source code of this file.

Functions

byte_t * blaze::alignedAllocate (size_t size, size_t alignment)
 Aligned array allocation.
void blaze::alignedDeallocate (const void *address) noexcept
 Deallocation of aligned memory.
template<typename T, EnableIf_t< IsBuiltin_v< T > > * = nullptr>
T * blaze::allocate (size_t size)
 Aligned array allocation for built-in data types.
template<typename T, DisableIf_t< IsBuiltin_v< T > > * = nullptr>
T * blaze::allocate (size_t size)
 Aligned array allocation for user-specific class types.
template<typename T, EnableIf_t< IsBuiltin_v< T > > * = nullptr>
void blaze::deallocate (T *address) noexcept
 Deallocation of memory for built-in data types.
template<typename T, DisableIf_t< IsBuiltin_v< T > > * = nullptr>
void blaze::deallocate (T *address)
 Deallocation of memory for user-specific class types.

Detailed Description

Header file for memory allocation and deallocation functionality.

Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved

This file is part of the Blaze library. You can redistribute it and/or modify it under the terms of the New (Revised) BSD License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the names of the Blaze development group nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ allocate()

template<typename T, DisableIf_t< IsBuiltin_v< T > > * = nullptr>
T * blaze::allocate ( size_t size)

Aligned array allocation for user-specific class types.

Parameters
sizeThe number of elements of the given type to allocate.
Returns
Pointer to the first element of the aligned array.
Exceptions
std::bad_allocAllocation failed.

The allocate() function provides the functionality to allocate memory based on the alignment restrictions of the given user-specific class type. For instance, in case the given type has the requirement to be 32-byte aligned, the returned pointer is guaranteed to be 32-byte aligned. Additionally, all elements of the array are guaranteed to be default constructed. Note that the allocate() function provides exception safety similar to the new operator: In case any element throws an exception during construction, all elements that have already been constructed are destroyed in reverse order and the allocated memory is deallocated again.

◆ deallocate()

template<typename T, DisableIf_t< IsBuiltin_v< T > > * = nullptr>
void blaze::deallocate ( T * address)

Deallocation of memory for user-specific class types.

Parameters
addressThe address of the first element of the array to be deallocated.
Returns
void

This function deallocates the given memory that was previously allocated via the allocate() function.