Memory

Description

Allocators, deallocators and memory manipulation.

Macros

#define BS_PVT_DELETE(T, ptr)
 
#define BS_PVT_DELETE_A(T, ptr, Alloc)
 

Typedefs

typedef std::basic_string< char, std::char_traits< char >, StdAlloc< char, FrameAlloc > > FrameString
 String allocated with a frame allocator. More...
 
typedef std::basic_string< wchar_t, std::char_traits< wchar_t >, StdAlloc< wchar_t, FrameAlloc > > FrameWString
 WString allocated with a frame allocator. More...
 
template<typename T , typename A = StdAlloc<T, FrameAlloc>>
using FrameVector = std::vector< T, A >
 Vector allocated with a frame allocator. More...
 
template<typename T , typename A = StdAlloc<T, FrameAlloc>>
using FrameStack = std::stack< T, std::deque< T, A > >
 Stack allocated with a frame allocator. More...
 
template<typename T , typename A = StdAlloc<T, FrameAlloc>>
using FrameQueue = std::queue< T, std::deque< T, A >>
 Queue allocated with a frame allocator. More...
 
template<typename T , typename P = std::less<T>, typename A = StdAlloc<T, FrameAlloc>>
using FrameSet = std::set< T, P, A >
 Set allocated with a frame allocator. More...
 
template<typename K , typename V , typename P = std::less<K>, typename A = StdAlloc<std::pair<const K, V>, FrameAlloc>>
using FrameMap = std::map< K, V, P, A >
 Map allocated with a frame allocator. More...
 
template<typename T , typename H = std::hash<T>, typename C = std::equal_to<T>, typename A = StdAlloc<T, FrameAlloc>>
using FrameUnorderedSet = std::unordered_set< T, H, C, A >
 UnorderedSet allocated with a frame allocator. More...
 
template<typename K , typename V , typename H = std::hash<K>, typename C = std::equal_to<K>, typename A = StdAlloc<std::pair<const K, V>, FrameAlloc>>
using FrameUnorderedMap = std::unordered_map< K, V, H, C, A >
 UnorderedMap allocated with a frame allocator. More...
 
template<typename T >
using SPtr = std::shared_ptr< T >
 Smart pointer that retains shared ownership of an project through a pointer. More...
 
template<typename T , typename Alloc = GenAlloc>
using UPtr = std::unique_ptr< T, decltype(&bs_delete< T, Alloc >)>
 Smart pointer that retains shared ownership of an project through a pointer. More...
 

Functions

BS_UTILITY_EXPORT FrameAlloc & gFrameAlloc ()
 Returns a global, application wide FrameAlloc. More...
 
BS_UTILITY_EXPORT UINT8 * bs_frame_alloc (UINT32 numBytes)
 Allocates some memory using the global frame allocator. More...
 
BS_UTILITY_EXPORT UINT8 * bs_frame_alloc_aligned (UINT32 count, UINT32 align)
 Allocates the specified number of bytes aligned to the provided boundary, using the global frame allocator. More...
 
BS_UTILITY_EXPORT void bs_frame_free (void *data)
 Deallocates memory allocated with the global frame allocator. More...
 
BS_UTILITY_EXPORT void bs_frame_free_aligned (void *data)
 Frees memory previously allocated with bs_frame_alloc_aligned(). More...
 
template<class T >
T * bs_frame_alloc ()
 Allocates enough memory to hold the object of specified type using the global frame allocator, but does not construct the object.
 
template<class T >
T * bs_frame_new (UINT32 count=0)
 Allocates enough memory to hold the object(s) of specified type using the global frame allocator, and constructs them.
 
template<class T , class... Args>
T * bs_frame_new (Args &&...args, UINT32 count=0)
 Allocates enough memory to hold the object(s) of specified type using the global frame allocator, and constructs them.
 
template<class T >
void bs_frame_delete (T *data)
 Destructs and deallocates an object allocated with the global frame allocator. More...
 
template<class T >
void bs_frame_delete (T *data, UINT32 count)
 Destructs and deallocates an array of objects allocated with the global frame allocator. More...
 
BS_UTILITY_EXPORT void bs_frame_mark ()
 Starts a new frame. More...
 
BS_UTILITY_EXPORT void bs_frame_clear ()
 Deallocates all allocated memory since the last call to markFrame() (or all the memory if there was no call to markFrame()). More...
 
template<class Alloc >
void * bs_alloc (UINT32 count)
 Allocates the specified number of bytes. More...
 
template<class T , class Alloc >
T * bs_alloc ()
 Allocates enough bytes to hold the specified type, but doesn't construct it. More...
 
template<class T , class Alloc >
T * bs_newN (UINT32 count)
 Creates and constructs an array of count elements. More...
 
template<class Type , class Alloc , class... Args>
Type * bs_new (Args &&...args)
 Create a new object with the specified allocator and the specified parameters. More...
 
template<class Alloc >
void bs_free (void *ptr)
 Frees all the bytes allocated at the specified location. More...
 
template<class T , class Alloc = GenAlloc>
void bs_delete (T *ptr)
 Destructs and frees the specified object. More...
 
template<class T , class Alloc = GenAlloc>
void bs_deleteN (T *ptr, UINT32 count)
 Destructs and frees the specified array of objects. More...
 
template<class T >
T * bs_alloc ()
 Allocates enough bytes to hold the specified type, but doesn't construct it. More...
 
void * bs_alloc_aligned (UINT32 count, UINT32 align)
 Allocates the specified number of bytes aligned to the provided boundary. More...
 
void * bs_alloc_aligned16 (UINT32 count)
 Allocates the specified number of bytes aligned to a 16 bytes boundary. More...
 
template<class T >
T * bs_allocN (UINT32 count)
 Allocates enough bytes to hold an array of count elements the specified type, but doesn't construct them. More...
 
template<class T >
T * bs_newN (UINT32 count)
 Creates and constructs an array of count elements. More...
 
template<class Type , class... Args>
Type * bs_new (Args &&...args)
 Create a new object with the specified allocator and the specified parameters. More...
 
void bs_free_aligned (void *ptr)
 Frees memory previously allocated with bs_alloc_aligned(). More...
 
void bs_free_aligned16 (void *ptr)
 Frees memory previously allocated with bs_alloc_aligned16(). More...
 
void * bs_stack_alloc (UINT32 amount)
 Allocates the given amount of memory on the stack. More...
 
template<class T >
T * bs_stack_alloc ()
 Allocates enough memory to hold the specified type, on the stack, but does not initialize the object. More...
 
template<class T >
T * bs_stack_new (UINT32 count=0)
 Allocates enough memory to hold the specified type, on the stack, and constructs the object. More...
 
template<class T , class... Args>
T * bs_stack_new (Args &&...args, UINT32 count=0)
 Allocates enough memory to hold the specified type, on the stack, and constructs the object. More...
 
template<class T >
void bs_stack_delete (T *data)
 Destructs and deallocates last allocated entry currently located on stack. More...
 
template<class T >
void bs_stack_delete (T *data, UINT32 count)
 Destructs an array of objects and deallocates last allocated entry currently located on stack. More...
 
void bs_stack_free (void *data)
 Deallocates the given memory. More...
 
template<class Type , class AllocCategory , class... Args>
SPtr< Type > bs_shared_ptr_new (Args &&...args)
 Create a new shared pointer using a custom allocator category. More...
 
template<class Type , class... Args>
SPtr< Type > bs_shared_ptr_new (Args &&...args)
 Create a new shared pointer using the default allocator category. More...
 
template<class Type , class MainAlloc = GenAlloc, class PtrDataAlloc = GenAlloc>
SPtr< Type > bs_shared_ptr (Type *data)
 Create a new shared pointer from a previously constructed object. More...
 
template<class Type , class Alloc = GenAlloc>
UPtr< Type, Alloc > bs_unique_ptr (Type *data)
 Create a new unique pointer from a previously constructed object. More...
 
template<class Type , class Alloc , class... Args>
UPtr< Type > bs_unique_ptr_new (Args &&...args)
 Create a new unique pointer using a custom allocator category. More...
 
template<class Type , class... Args>
UPtr< Type > bs_unique_ptr_new (Args &&...args)
 Create a new unique pointer using the default allocator category. More...
 

Macro Definition Documentation

#define BS_PVT_DELETE (   T,
  ptr 
)
Value:
(ptr)->~T(); \
MemoryAllocator<GenAlloc>::free(ptr);
#define BS_PVT_DELETE_A (   T,
  ptr,
  Alloc 
)
Value:
(ptr)->~T(); \
MemoryAllocator<Alloc>::free(ptr);

Typedef Documentation

using FrameMap = std::map < K, V, P, A >

Map allocated with a frame allocator.

using FrameQueue = std::queue<T, std::deque<T, A>>

Queue allocated with a frame allocator.

using FrameSet = std::set < T, P, A >

Set allocated with a frame allocator.

using FrameStack = std::stack < T, std::deque<T, A> >

Stack allocated with a frame allocator.

typedef std::basic_string<char, std::char_traits<char>, StdAlloc<char, FrameAlloc> > FrameString

String allocated with a frame allocator.

using FrameUnorderedMap = std::unordered_map < K, V, H, C, A >

UnorderedMap allocated with a frame allocator.

using FrameUnorderedSet = std::unordered_set < T, H, C, A >

UnorderedSet allocated with a frame allocator.

using FrameVector = std::vector < T, A >

Vector allocated with a frame allocator.

typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, StdAlloc<wchar_t, FrameAlloc> > FrameWString

WString allocated with a frame allocator.

using SPtr = std::shared_ptr<T>

Smart pointer that retains shared ownership of an project through a pointer.

The object is destroyed automatically when the last shared pointer to the object is destroyed.

using UPtr = std::unique_ptr<T, decltype(&bs_delete<T, Alloc>)>

Smart pointer that retains shared ownership of an project through a pointer.

Reference to the object must be unique. The object is destroyed automatically when the pointer to the object is destroyed.

Function Documentation

void * bs_alloc ( UINT32  count)

Allocates the specified number of bytes.

T* bs::bs_alloc ( )

Allocates enough bytes to hold the specified type, but doesn't construct it.

T* bs::bs_alloc ( )

Allocates enough bytes to hold the specified type, but doesn't construct it.

void* bs::bs_alloc_aligned ( UINT32  count,
UINT32  align 
)

Allocates the specified number of bytes aligned to the provided boundary.

Boundary is in bytes and must be a power of two.

void* bs::bs_alloc_aligned16 ( UINT32  count)

Allocates the specified number of bytes aligned to a 16 bytes boundary.

T* bs::bs_allocN ( UINT32  count)

Allocates enough bytes to hold an array of count elements the specified type, but doesn't construct them.

void bs::bs_delete ( T *  ptr)

Destructs and frees the specified object.

void bs::bs_deleteN ( T *  ptr,
UINT32  count 
)

Destructs and frees the specified array of objects.

T * bs_frame_alloc ( UINT32  numBytes)

Allocates some memory using the global frame allocator.

Allocates enough memory to hold N objects of specified type using the global frame allocator, but does not construct the object.

Parameters
[in]numBytesNumber of bytes to allocate.
BS_UTILITY_EXPORT UINT8* bs::bs_frame_alloc_aligned ( UINT32  count,
UINT32  align 
)

Allocates the specified number of bytes aligned to the provided boundary, using the global frame allocator.

Boundary is in bytes and must be a power of two.

BS_UTILITY_EXPORT void bs::bs_frame_clear ( )

Deallocates all allocated memory since the last call to markFrame() (or all the memory if there was no call to markFrame()).

Note
Not thread safe.
void bs::bs_frame_delete ( T *  data)

Destructs and deallocates an object allocated with the global frame allocator.

Note
Must be called on the same thread the memory was allocated on.
void bs::bs_frame_delete ( T *  data,
UINT32  count 
)

Destructs and deallocates an array of objects allocated with the global frame allocator.

Note
Must be called on the same thread the memory was allocated on.
BS_UTILITY_EXPORT void bs::bs_frame_free ( void *  data)

Deallocates memory allocated with the global frame allocator.

Note
Must be called on the same thread the memory was allocated on.
BS_UTILITY_EXPORT void bs::bs_frame_free_aligned ( void *  data)

Frees memory previously allocated with bs_frame_alloc_aligned().

Note
Must be called on the same thread the memory was allocated on.
BS_UTILITY_EXPORT void bs::bs_frame_mark ( )

Starts a new frame.

Next call to clear() will only clear memory allocated past this point.

void bs_free ( void *  ptr)

Frees all the bytes allocated at the specified location.

void bs::bs_free_aligned ( void *  ptr)

Frees memory previously allocated with bs_alloc_aligned().

void bs::bs_free_aligned16 ( void *  ptr)

Frees memory previously allocated with bs_alloc_aligned16().

Type* bs::bs_new ( Args &&...  args)

Create a new object with the specified allocator and the specified parameters.

Type* bs::bs_new ( Args &&...  args)

Create a new object with the specified allocator and the specified parameters.

T* bs::bs_newN ( UINT32  count)

Creates and constructs an array of count elements.

T* bs::bs_newN ( UINT32  count)

Creates and constructs an array of count elements.

SPtr<Type> bs::bs_shared_ptr ( Type *  data)

Create a new shared pointer from a previously constructed object.

Pointer specific data will be allocated using the provided allocator category.

SPtr<Type> bs::bs_shared_ptr_new ( Args &&...  args)

Create a new shared pointer using a custom allocator category.

SPtr<Type> bs::bs_shared_ptr_new ( Args &&...  args)

Create a new shared pointer using the default allocator category.

T * bs_stack_alloc ( UINT32  amount)

Allocates the given amount of memory on the stack.

Allocates enough memory to hold N objects of the specified type, on the stack, but does not initialize the objects.

Parameters
[in]amountThe amount to allocate in bytes.
Note
Allocates the memory in the currently active block if it is large enough, otherwise a new block is allocated. If the allocation is larger than default block size a separate block will be allocated only for that allocation, making it essentially a slower heap allocator.
Each allocation comes with a 4 byte overhead.
Parameters
[in]amountNumber of entries of the requested type to allocate.
See also
MemStackInternal::alloc()
T* bs::bs_stack_alloc ( )

Allocates enough memory to hold the specified type, on the stack, but does not initialize the object.

See also
MemStackInternal::alloc()
void bs::bs_stack_delete ( T *  data)

Destructs and deallocates last allocated entry currently located on stack.

See also
MemStackInternal::dealloc()
void bs::bs_stack_delete ( T *  data,
UINT32  count 
)

Destructs an array of objects and deallocates last allocated entry currently located on stack.

See also
MemStackInternal::dealloc()
void bs::bs_stack_free ( void *  data)

Deallocates the given memory.

Data must be deallocated in opposite order then when it was allocated.

T* bs::bs_stack_new ( UINT32  count = 0)

Allocates enough memory to hold the specified type, on the stack, and constructs the object.

See also
MemStackInternal::alloc()
T* bs::bs_stack_new ( Args &&...  args,
UINT32  count = 0 
)

Allocates enough memory to hold the specified type, on the stack, and constructs the object.

See also
MemStackInternal::alloc()
UPtr<Type, Alloc> bs::bs_unique_ptr ( Type *  data)

Create a new unique pointer from a previously constructed object.

Pointer specific data will be allocated using the provided allocator category.

UPtr<Type> bs::bs_unique_ptr_new ( Args &&...  args)

Create a new unique pointer using a custom allocator category.

UPtr<Type> bs::bs_unique_ptr_new ( Args &&...  args)

Create a new unique pointer using the default allocator category.

BS_UTILITY_EXPORT FrameAlloc& bs::gFrameAlloc ( )

Returns a global, application wide FrameAlloc.

Each thread gets its own frame allocator.

Note
Thread safe.