libhatchet
Loading...
Searching...
No Matches
hxsystem_allocator_scope Class Reference

#include <hxmemory_manager.h>

Public Member Functions

 hxsystem_allocator_scope (hxsystem_allocator_t allocator_) hxattr_noexcept
 ~hxsystem_allocator_scope (void) hxattr_noexcept
hxattr_nodiscard size_t get_current_allocation_count (void) const
hxattr_nodiscard size_t get_current_bytes_allocated (void) const
hxattr_nodiscard size_t get_initial_allocation_count (void) const
hxattr_nodiscard size_t get_initial_bytes_allocated (void) const

Friends

hxinline void hxsystem_allocator_scope_init_ (hxsystem_allocator_scope *scope_, size_t allocation_count_, size_t bytes_allocated_)

Detailed Description

hxsystem_allocator_scope - An RAII class to set the current memory manager allocator for the current scope.

It automatically restores the previous allocator when the scope ends. It also resets stack allocators to their initial offsets thereby freeing any allocations made during the lifetime of this object. WARNING: Two threads cannot share a stack allocator using this mechanism without due caution. Wait for worker tasks to complete before freeing their temporary allocations. The closest thing in the standard is std::scoped_allocator_adaptor and it is a template nightmare.

Constructor & Destructor Documentation

◆ hxsystem_allocator_scope()

hxsystem_allocator_scope::hxsystem_allocator_scope ( hxsystem_allocator_t allocator_)

Constructor: Sets the current memory allocator to the specified ID.

  • allocator : The memory manager ID to set for this scope. May modify new allocator in a way that cannot be shared between threads.

◆ ~hxsystem_allocator_scope()

hxsystem_allocator_scope::~hxsystem_allocator_scope ( void )

Destructor restores the stored previous memory manager allocator ID.

May modify current allocator in a way that cannot be shared between threads.

Member Function Documentation

◆ get_current_allocation_count()

hxattr_nodiscard size_t hxsystem_allocator_scope::get_current_allocation_count ( void ) const

Gets the total number of allocations outstanding for this memory allocator.

There should be no system overhead. Allocations made directly to new, delete, malloc and free are not tracked by hxsystem_allocator_heap.

◆ get_current_bytes_allocated()

hxattr_nodiscard size_t hxsystem_allocator_scope::get_current_bytes_allocated ( void ) const

Gets the total number of bytes allocated outstanding for this memory allocator.

Freed bytes might not be reused until the scope closes. There may also be significant system overhead that is not being reported.

◆ get_initial_allocation_count()

hxattr_nodiscard size_t hxsystem_allocator_scope::get_initial_allocation_count ( void ) const
inline

Gets the number of allocations made when this scope was entered.

◆ get_initial_bytes_allocated()

hxattr_nodiscard size_t hxsystem_allocator_scope::get_initial_bytes_allocated ( void ) const
inline

Gets the number of bytes allocated when this scope was entered.

◆ hxsystem_allocator_scope_init_

hxinline void hxsystem_allocator_scope_init_ ( hxsystem_allocator_scope * scope_,
size_t allocation_count_,
size_t bytes_allocated_ )
friend

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