Public Member Functions | Private Attributes

nitro::MemoryHandler Class Reference

#include <utilities/memory_handler.h>

Collaboration diagram for nitro::MemoryHandler:
Collaboration graph
[legend]

List of all members.

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< MemoryDescriptionMemoryDesriptions

Detailed Description

Class stores information about all allocated memory blocks.

Author:
Dodonov A.A.

Definition at line 219 of file memory_handler.h.


Member Function Documentation

template<class stored_type >
stored_type * nitro::MemoryHandler::Allocate ( PointerInterface Ptr,
const std::size_t  ItemCount,
const std::string &  BlockDescription = "" 
)

Function allocates memory block.

Parameters:
Ptr - .
ItemCount - .
BlockDescription - Description of the allocated memory block.
Returns:
Pointer on the allocated memory block.
Exceptions:
nitro::exception Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

template<class stored_type >
void nitro::MemoryHandler::Copy ( stored_type *&  Ptr1,
stored_type *&  Ptr2 
)

This function is called when one pointer is initialized by another pointer.

Parameters:
Ptr1 - Pointer to initialize.
Ptr2 - Initalizing pointer.
Exceptions:
nitro::exception Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

template<class stored_type >
void nitro::MemoryHandler::Deallocate ( stored_type *  DeallocatingData  ) 

Function deallocates allocated memory block.

Parameters:
DeallocatingData - Pointer on the allocated memory block to be deallocated.
Exceptions:
nitro::exception Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Array with all information about allocated memory blocks.

Author:
Dodonov A.A.

Definition at line 310 of file memory_handler.h.

Referenced by Allocate(), Copy(), and Deallocate().


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

Generated by  doxygen 1.6.1