bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::malloc_allocator Class Reference

This stateless allocator performs all of its allocation calls using raw calls to 'malloc', and frees memory with 'free'. More...

#include <malloc_allocator.hpp>

Public Types

using default_alignment = std::integral_constant< std::size_t, alignof(std::max_align_t)>
 

Public Member Functions

 malloc_allocator ()=default
 Default-constructs a malloc_allocator.
 
 malloc_allocator (malloc_allocator &&other) noexcept=default
 Move-constructs a malloc_allocator from another allocator. More...
 
 malloc_allocator (const malloc_allocator &other) noexcept=default
 Copy-constructs a malloc_allocator from another allocator. More...
 
malloc_allocatoroperator= (malloc_allocator &&other) noexcept=default
 Move-assigns a malloc_allocator from another allocator. More...
 
malloc_allocatoroperator= (const malloc_allocator &other) noexcept=default
 Copy-assigns a malloc_allocator from another allocator. More...
 
owner< void * > try_allocate (std::size_t size, std::size_t align) noexcept
 Attempts to allocate memory of size size, returning nullptr on failure. More...
 
void deallocate (owner< void *> p, std::size_t size)
 Deallocates a pointer p with the allocation size of size. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Detailed Description

This stateless allocator performs all of its allocation calls using raw calls to 'malloc', and frees memory with 'free'.

Any alignment requests are ignored

Satisfies
Allocator
Satisfies
Stateless

Definition at line 59 of file malloc_allocator.hpp.

Constructor & Destructor Documentation

◆ malloc_allocator() [1/2]

bit::memory::malloc_allocator::malloc_allocator ( malloc_allocator &&  other)
defaultnoexcept

Move-constructs a malloc_allocator from another allocator.

Parameters
otherthe other malloc_allocator to move

◆ malloc_allocator() [2/2]

bit::memory::malloc_allocator::malloc_allocator ( const malloc_allocator other)
defaultnoexcept

Copy-constructs a malloc_allocator from another allocator.

Parameters
otherthe other malloc_allocator to copy

Member Function Documentation

◆ deallocate()

void bit::memory::malloc_allocator::deallocate ( owner< void *>  p,
std::size_t  size 
)

Deallocates a pointer p with the allocation size of size.

Parameters
pthe pointer to deallocate
sizethe size to deallocate

◆ info()

allocator_info bit::memory::malloc_allocator::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'malloc_allocator'. Use a named_malloc_allocator to override this

Returns
the info for this allocator

◆ operator=() [1/2]

malloc_allocator& bit::memory::malloc_allocator::operator= ( malloc_allocator &&  other)
defaultnoexcept

Move-assigns a malloc_allocator from another allocator.

Parameters
otherthe other malloc_allocator to move
Returns
reference to (*this)

◆ operator=() [2/2]

malloc_allocator& bit::memory::malloc_allocator::operator= ( const malloc_allocator other)
defaultnoexcept

Copy-assigns a malloc_allocator from another allocator.

Parameters
otherthe other malloc_allocator to copy
Returns
reference to (*this)

◆ try_allocate()

owner<void*> bit::memory::malloc_allocator::try_allocate ( std::size_t  size,
std::size_t  align 
)
noexcept

Attempts to allocate memory of size size, returning nullptr on failure.

The alignment is ignored for calls to this allocator. The alignment is always guaranteed to be at least alignof(std::max_align_t)

Parameters
sizethe size of this allocation
alignthe requested alignment (ignored)
Returns
the allocated pointer

The documentation for this class was generated from the following file: