#include <utilities/memory_handler.h>
Public Member Functions | |
template<class stored_type > | |
stored_type * | Allocate (PointerInterface *Ptr, const std::size_t ItemCount, const std::string &BlockDescription="") |
template<class stored_type > | |
void | Deallocate (stored_type *DeallocatingData) |
template<class stored_type > | |
void | Copy (stored_type *&Ptr1, stored_type *&Ptr2) |
Private Attributes | |
std::vector< MemoryDescription > | MemoryDesriptions |
Class stores information about all allocated memory blocks.
Definition at line 219 of file memory_handler.h.
stored_type * nitro::MemoryHandler::Allocate | ( | PointerInterface * | Ptr, | |
const std::size_t | ItemCount, | |||
const std::string & | BlockDescription = "" | |||
) |
Function allocates memory block.
Ptr | - . | |
ItemCount | - . | |
BlockDescription | - Description of the allocated memory block. |
nitro::exception | Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 347 of file memory_handler.h.
References nitro::exception::code(), MemoryDesriptions, and nitro::exception::what().
{ try { stored_type * Ptr( new stored_type[ ItemCount ] ); for( std::size_t i( 0 ) ; i < MemoryDesriptions.size() ; i++ ) { if( MemoryDesriptions[ i ].AddressIn( PtrI ) ) { MemoryDesriptions[ i ].RegisterPointer( PtrI ); } } MemoryDesriptions.push_back( MemoryDescription( ( void * )Ptr , sizeof( stored_type ) * ItemCount , BlockDescription ) ); return( Ptr ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryHandler::Allocate( PointerInterface * PtrI , const std::size_t ItemCount , const std::string & BlockDescription /* = "" */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryHandler::Allocate( PointerInterface * PtrI , const std::size_t ItemCount , const std::string & BlockDescription /* = "" */ )::An error occured" ) , 0 ) ); } }
void nitro::MemoryHandler::Copy | ( | stored_type *& | Ptr1, | |
stored_type *& | Ptr2 | |||
) |
This function is called when one pointer is initialized by another pointer.
Ptr1 | - Pointer to initialize. | |
Ptr2 | - Initalizing pointer. |
nitro::exception | Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 313 of file memory_handler.h.
References nitro::exception::code(), MemoryDesriptions, and nitro::exception::what().
{ try { for( std::size_t i( 0 ) ; i < MemoryDesriptions.size() ; i++ ) { if( MemoryDesriptions[ i ].AddressIn( Ptr1 ) ) { MemoryDesriptions[ i ].OnAssigned(); break; } } for( std::size_t i( 0 ) ; i < MemoryDesriptions.size() ; i++ ) { if( MemoryDesriptions[ i ].AddressIn( Ptr2 ) ) { MemoryDesriptions[ i ].OnCopied(); break; } } Ptr1 = Ptr2; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryHandler::Copy( stored_type & * Ptr1 , stored_type & * Ptr2 )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryHandler::Copy( stored_type & * Ptr1 , stored_type & * Ptr2 )::An error occured" ) , 0 ) ); } }
void nitro::MemoryHandler::Deallocate | ( | stored_type * | DeallocatingData | ) |
Function deallocates allocated memory block.
DeallocatingData | - Pointer on the allocated memory block to be deallocated. |
nitro::exception | Can throw exception of this type. It contains a description of the error and error code. |
Definition at line 375 of file memory_handler.h.
References nitro::exception::code(), MemoryDesriptions, and nitro::exception::what().
{ try { for( std::size_t i( 0 ) ; i < MemoryDesriptions.size() ; i++ ) { if( MemoryDesriptions[ i ].AddressIn( DeallocatingData ) ) { MemoryDesriptions[ i ].ReleaseNestedPointers(); delete [] DeallocatingData; MemoryDesriptions.erase( MemoryDesriptions.begin() + i ); } } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "MemoryHandler::Deallocate( stored_type * DeallocatingData )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "MemoryHandler::Deallocate( stored_type * DeallocatingData )::An error occured" ) , 0 ) ); } }
std::vector< MemoryDescription > nitro::MemoryHandler::MemoryDesriptions [private] |
Array with all information about allocated memory blocks.
Definition at line 310 of file memory_handler.h.
Referenced by Allocate(), Copy(), and Deallocate().