Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
hermes::ScopedTemporaryMemory Struct Reference

#include <memory_management.h>

Collaboration diagram for hermes::ScopedTemporaryMemory:

Public Member Functions

 ScopedTemporaryMemory (const ScopedTemporaryMemory &)=delete
 
ScopedTemporaryMemoryoperator= (const ScopedTemporaryMemory &)=delete
 
 ScopedTemporaryMemory (Arena *backing_arena)
 
 ~ScopedTemporaryMemory ()
 
 operator Arena * ()
 

Public Attributes

Arenaarena
 
size_t used
 

Detailed Description

A block of memory that can be used dynamically, but is deleted when exiting the current scope.

ScopedTemporaryMemory wraps an existing Arena. You can pass an instance of it as you would normally pass an Arena instance to PushSize and PushArray. The difference is that the memory is reclaimed once the scope in which ScopedTemporaryMemory is declared is exited. Note that there is no actual free happening. Rather, the existing Arena's used parameter is reset to where it was before the ScopedTemporaryMemory was created.

Example:

{
ScopedTemporaryMemory temp_memory(existing_arena_ptr);
MyStruct *scoped_array = PushArray<MyStruct>(temp_memory, num_elements);
for (int i = 0; i < num_elements; ++i) {
// ...
}
} // scoped_array memory is reclaimed here

Constructor & Destructor Documentation

◆ ScopedTemporaryMemory()

hermes::ScopedTemporaryMemory::ScopedTemporaryMemory ( Arena backing_arena)
inlineexplicit

Creates a ScopedTemporaryMemory from an existing, backing Arena.

Parameters
backing_arenaThe existing Arena backing the temporary memory.

◆ ~ScopedTemporaryMemory()

hermes::ScopedTemporaryMemory::~ScopedTemporaryMemory ( )
inline

Destructor. Restores the backing Arena's bytes in use to the saved used value, effectively reclaiming the memory that was used in this scope.

Member Function Documentation

◆ operator Arena *()

hermes::ScopedTemporaryMemory::operator Arena * ( )
inline

Allows passing a ScopedTemporaryMemory to functions that take an Arena without an explicit cast.

Member Data Documentation

◆ arena

Arena* hermes::ScopedTemporaryMemory::arena

An existing, backing Arena

◆ used

size_t hermes::ScopedTemporaryMemory::used

The stored number of bytes in use by the backing Arena


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