#include <utilities/memory_handler.h>
Public Member Functions | |
MemoryDescription (void *theMemoryBlock, const std::size_t theMemoryBlockSize, const std::string &theBlockDescription) | |
void | OnAssigned (void) |
void | OnCopied (void) |
bool | AddressIn (void *Address) |
void | RegisterPointer (PointerInterface *Ptr) |
void | ReleaseNestedPointers (void) |
Private Attributes | |
void * | MemoryBlock |
std::size_t | MemoryBlockSize |
std::string | BlockDescription |
std::size_t | ReferenceCounter |
std::vector< PointerInterface * > | NestedPointers |
Objects of this class stores allocated memory block's description.
Definition at line 39 of file memory_handler.h.
nitro::MemoryDescription::MemoryDescription | ( | void * | theMemoryBlock, | |
const std::size_t | theMemoryBlockSize, | |||
const std::string & | theBlockDescription | |||
) |
Constructor.
theMemoryBlock | - Pointer on the allocated memory block. | |
theMemoryBlockSize | - Size of the allocated memory block. | |
theBlockDescription | - String description of the allocated memory block. |
Definition at line 8 of file memory_handler.cpp.
References BlockDescription, nitro::exception::code(), MemoryBlock, MemoryBlockSize, ReferenceCounter, and nitro::exception::what().
{ try { MemoryBlock = theMemoryBlock; MemoryBlockSize = theMemoryBlockSize; BlockDescription = theBlockDescription; ReferenceCounter = 1; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::An error occured" ) , 0 ) ); } }
bool nitro::MemoryDescription::AddressIn | ( | void * | Address | ) |
Function validates does address Address belongs to the allocated memory block.
Address | - Validating address. |
nitro::exception | Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 62 of file memory_handler.cpp.
References nitro::exception::code(), MemoryBlock, MemoryBlockSize, and nitro::exception::what().
Referenced by RegisterPointer().
{ try { return( MemoryBlock >= Address && Address <= ( ( char * )MemoryBlock ) + MemoryBlockSize ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::An error occured" ) , 0 ) ); } }
void nitro::MemoryDescription::OnAssigned | ( | void | ) |
Function is called at the moment when pointer is set with the new address.
Definition at line 30 of file memory_handler.cpp.
References nitro::exception::code(), ReferenceCounter, and nitro::exception::what().
{ try { ReferenceCounter--; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::An error occured" ) , 0 ) ); } }
void nitro::MemoryDescription::OnCopied | ( | void | ) |
Function is called at the moment when pointer is used to initialize another pointer.
Definition at line 46 of file memory_handler.cpp.
References nitro::exception::code(), ReferenceCounter, and nitro::exception::what().
{ try { ReferenceCounter++; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::An error occured" ) , 0 ) ); } }
void nitro::MemoryDescription::RegisterPointer | ( | PointerInterface * | Ptr | ) |
Function registers pointer for the described memory block.
Ptr | - Pointer to register. |
nitro::exception | - Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 78 of file memory_handler.cpp.
References AddressIn(), nitro::exception::code(), NestedPointers, and nitro::exception::what().
{ try { if( AddressIn( ( void * ) Ptr ) ) { NestedPointers.push_back( Ptr ); } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) ); } }
void nitro::MemoryDescription::ReleaseNestedPointers | ( | void | ) |
Function releases all allocated memory throgh all registred nested pointers.
nitro::exception | - Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 97 of file memory_handler.cpp.
References nitro::exception::code(), NestedPointers, and nitro::exception::what().
{ try { for( std::size_t i( 0 ) ; i < NestedPointers.size() ; i++ ) { NestedPointers[ i ]->Release(); } NestedPointers.erase( NestedPointers.begin() , NestedPointers.end() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) ); } }
std::string nitro::MemoryDescription::BlockDescription [private] |
String description of the allocated memory block.
Definition at line 182 of file memory_handler.h.
Referenced by MemoryDescription().
void* nitro::MemoryDescription::MemoryBlock [private] |
Pointer on the allocated memory block.
Definition at line 158 of file memory_handler.h.
Referenced by AddressIn(), and MemoryDescription().
std::size_t nitro::MemoryDescription::MemoryBlockSize [private] |
Size of the allocated memory block.
Definition at line 170 of file memory_handler.h.
Referenced by AddressIn(), and MemoryDescription().
std::vector< PointerInterface * > nitro::MemoryDescription::NestedPointers [private] |
Array contains all pointers from the described memory block.
Definition at line 206 of file memory_handler.h.
Referenced by RegisterPointer(), and ReleaseNestedPointers().
std::size_t nitro::MemoryDescription::ReferenceCounter [private] |
Reference counter.
Definition at line 194 of file memory_handler.h.
Referenced by MemoryDescription(), OnAssigned(), and OnCopied().