์งํ ๊ธฐ๊ฐ: 2023/03/01 โ 2023/08/13 ์คํฌ: C++, CMake
- ECS๋ฅผ ์ํ ๋ถ์์ ์ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์ฑ
- Log Project
- Memory Project
- ์ธ์ด
- C++
- ์์ง ์์ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๊ธฐ ์ํ ๊ธฐ๋ฅ
- Log ์ ๋ณด๋ค์ ๋ฐ๋ก ์ ์ฅ์ํฌ ์๋ ์์ด์ผ ํจ
- ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋๋ ์ค ํ์๊ฐ ์์
- Info : ์ผ๋ฐ์ ์ธ ์ ๋ณด
- Warn : ๋ฐํ์ ์๋ฌ๊น์ง๋ ์๋์ง๋ง, ์ฃผ์ํด์ผ ๋ ์ ๋ณด
- Error: ๋ฐํ์ ์๋ฌ๋ฅผ ์ ๋ฐํ๊ฑฐ๋, ์์ธ์ฒ๋ฆฌ๊ฐ ๋์ด์ง ์ ๋ณด
- ๋ฉ๋ชจ๋ฆฌ ์ด๊ธฐํ ๋ฐ ํ ๋น ์์ ์ ํจ์จ์ ์ผ๋ก ์ฒ๋ฆฌํ๊ธฐ ์ํจ
- ์ฌ๋ฌ ์ข ๋ฅ์ ์ธ์คํด์ค๋ฅผ ์ค์ ๊ด๋ฆฌํ๊ธฐ ์ํจ
- ์ค๋งํธ ํฌ์ธํฐ์ ์ ์ฌํ ํํ๋ก ๊ตฌํ
- ECS ์์์ ๊ฐ์ฒด๋ค์ ํฌ์ธํฐ๋ฅผ ๋ฐํํ ๊ฒฝ์ฐ, ๋ฉ๋ชจ๋ฆฌ ๊ด๋ จ ๋ง์ ๋ฌธ์ ๊ฐ ์๊ธธ ์ ์์
- Memory Manager์์๋ง ์๋ฉธ์ด ๊ฐ๋ฅํ๋๋ก ์ค์
- Log, Memory Project๋ค์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ์์ฑํ ์ ์๋ CMakelists ์ค์
- Github์ ํด๋น Repository๋ฅผ ์์ฑํ๊ณ , ์ฐ๊ฒฐํ์ฌ ์์กด์ฑ ์ค์ ํ ํ ์ฌ์ฉ
- IMemoryPool
- MemoryPool( Parent : IMemoryPool )
- MemoryPtr
- MemoryManager
- Log
- IMemoryPool
-
MemoryPool๋ฅผ ์ฌ์ฉํ๋ ๊ฐ์ฒด๋ค์ ์ํ ์ธํฐํ์ด์ค
class IMemoryPool { public: IMemoryPool() {} virtual ~IMemoryPool() {} public: virtual void Init() = 0; virtual void Destroy() = 0; virtual bool CheckFull() = 0; virtual bool CheckEmpty() = 0; public : virtual const size_t& GetTotalSize() = 0; virtual const size_t& GetObjectSize() = 0; virtual char*& GetStartPtr() = 0; };
-
-
MemoryPool
- ์ฃผ๋ ์ญํ
- ์ค์ ๋ก ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋น ๋ฐ ํด์ ํ๋ ์ฃผ๋ ๊ฐ์ฒด
- ์ ์ฒด ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ๊บผ๋ฒ์ ํ ๋น ๋ฐ์ผ๋ฉฐ, ์ด๊ธฐํ์ ์๋ฉธ์๋ก ์ธ์คํด์ค๋ฅผ ๊ด๋ฆฌ
- ๋ฉ๋ชจ๋ฆฌ ๊ด๋ จ
-
MemoryPool์์ ์ฒ์์ ํ ๋น ๋ฐ์ ์ฃผ์์ ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ์ ๋ํ ์ค๋ธ์ ํธ ํฌ๊ธฐ์ ์ธ๋ฑ์ค ์ ๋ณด๋ก ๊ด๋ฆฌ
- ์๋ฅผ ๋ค์ด
- ํ ๋น ๋ฐ์ ์ฃผ์ : 01
- ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ : 8
- ์ค๋ธ์ ํธ ์ฌ์ด์ฆ : 2
- ๊ฐ๋ฅํ ์ค๋ธ์ ํธ ์ธ๋ฑ์ค( ์ฃผ์ ) : 0( 01 ), 1( 03 ), 2( 05 ), 3(07 )
- ์๋ฅผ ๋ค์ด
-
์ฒ์ MemoryPool์ด ์์ฑ๋ ๋, ์ฃผ์ด์ง ํ ๋น ์ฌ์ด์ฆ๋ฅผ ํ์ธ ํ ํ ๋น ๋ฐ์
-
void Init()
- malloc์ ํตํ์ฌ ๋ฉ๋ชจ๋ฆฌ ํ ๋น๋ง ์งํ
- m_CanConstruct์ ์ฌ์ฉ๊ฐ๋ฅํ Index ๊ธฐ์
- m_CanConstruct
- ์ด๊ธฐํ์ํฌ ์ ์๋ ์ธ์คํด์ค๋ค์ ํฌ์ธํฐ์ ๋ํ ์ธ๋ฑ์ค ์ ๋ณด๋ฅผ ์ง๋ ํ
- m_CanDestruct
- ์๋ฉธ์ํฌ ์ ์๋ ์ธ์คํด์ค๋ค์ ํฌ์ธํฐ์ ๋ํ ์ธ๋ฑ์ค ์ ๋ณด๋ฅผ ์ง๋ ํ
void Init() { m_pStart = static_cast<char*>( std::malloc( m_TotalSize ) ); for ( size_t I = 0; I < m_TotalSize / m_ObjectSize; I++ ) { m_CanConstruct.push( static_cast<int>( I ) ); } m_CanDestruct.clear(); m_CanDestruct.reserve( static_cast<int>( m_TotalSize / m_ObjectSize ) ); return; }
-
-
์ฃผ์ด์ง ๋ฉ๋ชจ๋ฆฌ๋ฅผ MemoryPool์ด ์๋ฉธ๋ ๋๊น์ง ์ ์ง๋จ
-
- ์ธ์คํด์ค ๊ด๋ฆฌ ๊ด๋ จ
- ์์ฑ๊ณผ ์๋ฉธ์ ์ธ์คํด์ค์ ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํ์ฌ์ ๊ด๋ฆฌ
-
m_CanConstruct
- ์ด๊ธฐํ์ํฌ ์ ์๋ ์ธ์คํด์ค๋ค์ ํฌ์ธํฐ์ ๋ํ ์ธ๋ฑ์ค ์ ๋ณด๋ฅผ ์ง๋ ํ
-
m_CanDestruct
- ์๋ฉธ์ํฌ ์ ์๋ ์ธ์คํด์ค๋ค์ ํฌ์ธํฐ์ ๋ํ ์ธ๋ฑ์ค ์ ๋ณด๋ฅผ ์ง๋ ํ
-
์์ฑ ๊ด๋ จ
- template< typename โฆ Args >
T Construct( Args&&โฆ args )*
- CheckFull()
- ํด๋น MemoryPool์ด ๊ฐ๋ ์ฐผ๋์ง ํ์ธ
- m_CanConstruct๊ฐ ๋น์์ ์, true
- ์ด๊ธฐํ ๊ฐ๋ฅํ ์ธ๋ฑ์ค๋ฅผ ์ด์ฉํ์ฌ ์์น์ง์ new๋ฅผ ํธ์ถ
- CheckFull()
template< typename ... Args > T* Construct( Args&&... args ) { if ( CheckFull() ) { throw Except( " MemoryPool | %s | %s | This MemoryPool is full ", __FUNCTION__, typeid( T ).name() ); } int Index = m_CanConstruct.front(); m_CanDestruct.push_back( Index ); m_CanConstruct.pop(); T* Ptr = new ( GetStartPtr() + Index * GetObjectSize() ) T( std::forward<Args>( args ) ... ); Log::Info( " Instance | %s | %p | Create new ", typeid( T ).name(), Ptr ); return Ptr; }
- template< typename โฆ Args >
T Construct( Args&&โฆ args )*
-
์๋ฉธ ๊ด๋ จ
-
void Destruct( T& Ptr )*
- Ptr์ ์ด์ฉํ์ฌ์, MemoryPool์์ ์๋ฉธ์ํฌ ์ ์๋ Index ํ์ธ
- Index๊ฐ ์์ ๊ฒฝ์ฐ
- ํด๋น ์ธ์คํด์ค์ ์๋ฉธ์๋ฅผ ํธ์ถํ๊ณ nullptr ๊ธฐ์
- m_CanConstruct์ m_CanDestruct ์ต์ ํ
void Destruct( T*& Ptr ) { int Index = static_cast<int>( ( reinterpret_cast<char*>( Ptr ) - GetStartPtr() ) / GetObjectSize() ); auto ITR = std::remove( m_CanDestruct.begin(), m_CanDestruct.end(), Index ); if ( ITR != m_CanDestruct.end() ) { Log::Info( " Instance | %s | %p | Delete ", typeid( T ).name(), Ptr ); m_CanDestruct.erase( ITR, m_CanDestruct.end() ); Ptr->~T(); Ptr = nullptr; m_CanConstruct.push( Index ); } else { throw Except(" Instance | %s | %p | This memorypool has not this instance ", typeid( T ).name(), Ptr ); } }
-
-
- ์์ฑ๊ณผ ์๋ฉธ์ ์ธ์คํด์ค์ ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํ์ฌ์ ๊ด๋ฆฌ
- ์ฃผ๋ ์ญํ
-
MemoryPtr
-
์ฃผ๋ ์ญํ
- ์ธ๋ถ์์์ ํฌ์ธํฐ ํด์ ์ ๋ํ ๋ณดํธ์ญํ ๋ฐ ์บ์คํ ์ ์ํ ์ฉ๋
-
ํฌ์ธํฐ ๊ด๋ จ
-
ํฌ์ธํฐ๋ฅผ ํด์ ํ ์ ์๋ ์ญํ ์ ์ค์ง MemoryManager
- template< typename U >
friend class MemoryPtr;
- ๋ค๋ฅธ ํ ํ๋ฆฟ MemoryPtr์์๋ ์๋ก private ๋ฉค๋ฒ ๋ณ์์ ์ ๊ทผํ ์ ์๋๋ก
private : friend class MemoryManager; template< typename U > friend class MemoryPtr;
- template< typename U >
friend class MemoryPtr;
-
RTTI๋ฅผ ํตํ ์บ์คํ ์ด ๊ฐ๋ฅ
template< typename U > bool CheckValidityofCopy( U*& otherPtr ) { if ( otherPtr == nullptr ) { Log::Warn( " MPTR | %s | %s | The pointer is empty ", __FUNCTION__, typeid( T ).name() ); return false; } if ( m_Ptr != nullptr ) { Log::Warn( " MPTR | %s | %s | Already pointer existed %p", __FUNCTION__, typeid( T ).name(), m_Ptr ); return false; } T* mainPtr = dynamic_cast< T* >( otherPtr ); if ( mainPtr == nullptr ) { Log::Warn( " MPTR | %s | %s | No inheritance relationship with %s ", __FUNCTION__, typeid( T ).name(), typeid( U ).name() ); return false; } m_Ptr = mainPtr; return true; }
-
-
MemoryPool ๊ด๋ จ
- MemoryPool์ Start Pointer๋ฅผ ์ง๋๊ณ ์์ด์ MemoryManager์์ ๊ด๋ฆฌ๊ฐ ํธ๋ฆฌํ๊ธฐ ์ํจ
public : char* GetPoolPtr() { return m_PoolPtr; } void SetPoolPtr( char* Start ) { bool Check = ( Start != m_PoolPtr ) || ( Start != nullptr ); if ( Check ) m_PoolPtr = Start; } private : T* m_Ptr = nullptr; char* m_PoolPtr;
-
- MemoryManager
-
์ฃผ๋ ์ญํ
- MemoryPool์ ์์ฑ ๋ฐ ์ญ์ ํ๋ ์ญํ
- ์ธ์คํด์ค๋ฅผ ์ด๊ธฐํ ๋ฐ ์๋ฉธํ๋ ์ญํ
-
MemoryPool ๊ด๋ จ
-
์ ๊ทผ ๋ฐฉ์
-
Start Pointer๋ก MemoryPool์ ์ ๊ทผ
-
Start Pointer์ ๋ฆฌ์คํธ๋ Type๋ณ๋ก ์ ์ฅ
using IMemoryPoolPtrList = std::list< char* >; using IMemoryPoolMap = std::unordered_map< char*, IMemoryPool* >; using TypePoolPtrListMap = std::unordered_map< const std::type_info*, IMemoryPoolPtrList >; IMemoryPoolMap m_IMemoryPoolMap; TypePoolPtrListMap m_TypePoolPtrListMap;
-
-
์์ฑ ๊ด๋ จ
-
template< typename T > void CreateMemoryPool( size_t Size )
- m_IMemoryPoolMap
- Start Pointer์ ์ฌ์ฉํ์ฌ IMemoryPool์ ์ ๊ทผํ๊ธฐ ์ํ ์๋ฃ
- Key : Start Pointer
- Value : IMemoryPool Pointer
- m_TypePoolPtrListMap
- Type ๋ฐ์ดํฐ๋ฅผ ์ด์ฉํ์ฌ Start Pointer๋ค ๋ฐ์ดํฐ๋ค์ ์ ๊ทผํ๊ธฐ ์ํ ์๋ฃ
- Key : const std::type_info*
- Value : Start Pointer Set
template< typename T > void CreateMemoryPool( size_t Size ) { IMemoryPool* iMemoryPool = new MemoryPool<T>( Size ); iMemoryPool->Init(); m_IMemoryPoolMap[ iMemoryPool->GetStartPtr() ] = iMemoryPool; m_TypePoolPtrListMap[ &typeid( T ) ].push_back( iMemoryPool->GetStartPtr() ); Log::Info( " MemoryManager | %s | Pool Ptr %p - Start Ptr %p | Create new memory pool ", typeid( T ).name(), iMemoryPool, iMemoryPool->GetStartPtr() ); }
- m_IMemoryPoolMap
-
-
-
์ธ์คํด์ค ๊ด๋ จ
-
์์ฑ ๊ด๋ จ
-
ํ๋์ MemoryPool์ ํ๋์ ์ธ์คํด์ค๋ง ์์ฑํ ์ง, ์ฌ๋ฌ๊ฐ๋ฅผ ์์ฑํ ์ง ์ค์ ๊ฐ๋ฅ
-
template< typename T, typenameโฆ Args > MemoryPtr Create( Args&&โฆ args )
- ์ฌ๋ฌ ๊ฐ์ ์ธ์คํด์ค๋ฅผ ์์ฑ
-
template< typename T, typenameโฆ Args > MemoryPtr CreateOne( Args&&โฆ args )
- ํ๋์ ์ธ์คํด์ค๋ง์ ์์ฑ
template< typename T, typename... Args > MemoryPtr<T> Create( Args&&... args ) { size_t Size = m_DefaultSize; return MainCreate<T>( Size, std::forward<Args>( args ) ... ); } template< typename T, typename... Args> MemoryPtr<T> CreateOne( Args&&... args ) { size_t Size = sizeof( T ); return MainCreate<T>( Size, std::forward<Args>( args) ... ); }
-
-
IMemoryPool list์์ ์ด๊ธฐํ ๊ฐ๋ฅํ MemoryPool์ ์ฐพ์์ ์ธ์คํด์ค ์์ฑ ์งํ
-
template< typename T, typenameโฆ Args > MemoryPtr MainCreate( size_t Size, Args&&โฆ args )
- HasList()
- ํด๋น T ํ์ ์ ๋ํ IMemoryPool List๊ฐ ์๋์ง ํ์ธ
- CreateList()
- ํด๋น T ํ์ ์ ๋ํ IMemoryPool List ์์ฑ
- GetList()
- ํด๋น T ํ์ ์ ๋ํ IMemoryPool ํฌ์ธํฐ๋ฅผ ์ง๋ List์ ๋ ํผ๋ฐ์ค ํธ์ถ
- GetMemoryPool( char Start )*
- ํด๋น T ํ์ ์ Start Pointer๋ฅผ ์ง๋ IMemoryPool Pointer ๋ฐํ
- IMemoryPool List๋ฅผ ๋์์๋ถํฐ ํธ์ถํ๋ฉฐ, ์์ฑ ๊ฐ๋ฅ ์ฌ๋ถ ํ์ธ
- ์ ๋ถ ๋ถ๊ฐ๋ฅ
- ์ ์ฒด์ IMemoryPool์ด ๊ฐ๋ ์ฐผ์ ์, ์๋ก์ด MemoryPool ์์ฑ
- MainCreate ํจ์๋ฅผ ์ฌ๊ท์ ์ผ๋ก ํธ์ถ
- ๊ฐ๋ฅ
- MemoryPool์ ํธ์ถ ๋ฐ ๊ฐ์ฒด ์์ฑ
- ์ ๋ถ ๋ถ๊ฐ๋ฅ
template< typename T, typename... Args > MemoryPtr<T> MainCreate( size_t Size, Args&&... args ) { if ( !HasList<T>() ) CreateList<T>( Size ); IMemoryPoolPtrList& PoolPtrList = GetList<T>(); for ( auto ITR = PoolPtrList.rbegin(); ITR != PoolPtrList.rend(); ITR++ ) { MemoryPool<T>* memoryPool = GetMemoryPool<T>( *ITR ); if ( memoryPool->CheckFull() ) continue; else { MemoryPtr<T> mPtr = memoryPool->Construct( std::forward<Args>( args ) ... ); mPtr.SetPoolPtr( memoryPool->GetStartPtr() ); return mPtr; } } CreateMemoryPool<T>( Size ); return MainCreate<T>( Size, std::forward<Args>( args ) ... ); }
- HasList()
-
-
-
์ญ์ ๊ด๋ จ
-
MemoryPtr์์ ์๋ MemoryPool์ Start Ptr ๋ฉค๋ฒ ๋ณ์๋ฅผ ํตํ์ฌ์ ์ญ์
- template< typename T >
void Delete( MemoryPtr& mPtr )
- GetPoolPtr()
- ํด๋น MemoryPtr์ Ptr๊ฐ ์๋ MemoryPool์ Start Ptr ๋ฐํ
- HasMemoryPool( char Start )*
- ํด๋น T ํ์ ์์ Start์ Start Pointer๋ฅผ ๊ฐ๋ MemoryPool ํ์ธ
- GetPoolPtr()
template< typename T > void Delete( MemoryPtr<T>& mPtr ) { if ( !HasList<T>() ) return; char* PoolPtr = mPtr.GetPoolPtr(); bool Check = HasMemoryPool<T>( PoolPtr ); if ( Check ) { MemoryPool<T>* memoryPool = GetMemoryPool<T>( PoolPtr ); memoryPool->Destruct( mPtr.GetPtr() ); if ( memoryPool->CheckEmpty() ) DeletePool<T>( PoolPtr ); } }
- template< typename T >
void Delete( MemoryPtr& mPtr )
-
-
-
-
์ค์ ๊ด๋ฆฌ
-
BUILD_STATIC_LIBRARY
- true : ์ ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- false : ๋์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
-
INSTALL_DEMO_FILE
- true : Demofile ์ค์น
- false : Demofile ๋ฏธ์ค์น
OPTION( BUILD_STATIC_LIBRARY "Set option for the library which is static or dynamic" OFF ) OPTION( INSTALL_DEMO_FILE "Install demofile for memorymanager" ON ) ## Set Option for install lib, header files' path SET( PREFIX_DIR ${MAIN_DIR}/build/Prefix CACHE PATH "Prefix Path" ) SET( INCLUDE_DIR ${MAIN_DIR}/build/include CACHE PATH "Header files Path" ) SET( ARC_DIR ${MAIN_DIR}/build/arc CACHE PATH "Archieve files Path" ) SET( LIB_DIR ${MAIN_DIR}/build/lib CACHE PATH "Library files Path" ) SET( BIN_DIR ${MAIN_DIR}/build/bin CACHE PATH "Execute files Path" ) SET( CMAKE_BUILD_TYPE Debug CACHE STRING "Build Type" )
-
-
์ฐ๊ฒฐ ๊ด๋ฆฌ
-
Log Project
#### Log ----------------------------------- # MESSAGE( STATUS "Log Project - Linking ... ") EXTERNALPROJECT_ADD( LogProject GIT_REPOSITORY GIT_REPOSITORY https://github.com/Winteradio/Log.git GIT_TAG "v2.2.0" PREFIX ${PREFIX_DIR}/LogProject UPDATE_COMMAND "" PATCH_COMMAND "" TEST_COMMAND "" INSTALL_COMMAND "" CMAKE_ARGS -DINCLUDE_DIR=${INCLUDE_DIR} -DLIB_DIR=${LIB_DIR} -DBIN_DIR=${BIN_DIR} -DARC_DIR=${ARC_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_STATIC_LIBRARY=${BUILD_STATIC_LIBRARY} -DINSTALL_DEMO_FILE=OFF ) LIST( APPEND DEP_INCLUDE ${INCLUDE_DIR} ) LIST( APPEND DEP_LIST LogProject ) LIST( APPEND DEP_LIBS ${ARC_DIR}/LogProject.${STATIC_LIB} ) MESSAGE( STATUS "Log Project - Done") #### Log ----------------------------------- #
-
Memory Project
#### Memory Pool ----------------------------------- # MESSAGE(STATUS "Memory Project - Linking ...") EXTERNALPROJECT_ADD( MemoryProject GIT_REPOSITORY GIT_REPOSITORY https://github.com/Winteradio/MemoryPool.git GIT_TAG "v4.2.0" PREFIX ${PREFIX_DIR}/MemoryProject UPDATE_COMMAND "" PATCH_COMMAND "" TEST_COMMAND "" INSTALL_COMMAND "" CMAKE_ARGS -DPREFIX_DIR=${PREFIX_DIR} -DINCLUDE_DIR=${INCLUDE_DIR} -DLIB_DIR=${LIB_DIR} -DBIN_DIR=${BIN_DIR} -DARC_DIR=${ARC_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_STATIC_LIBRARY=${BUILD_STATIC_LIBRARY} -DINSTALL_DEMO_FILE=${INSTALL_DEMO_FILE} -DINSTALL_MEMORY_MANAGER=ON ) LIST( APPEND DEP_INCLUDE ${INCLUDE_DIR} ) LIST( APPEND DEP_LIST MemoryProject ) LIST( APPEND DEP_LIBS ${ARC_DIR}/MemoryProject.${STATIC_LIB} ) LIST( APPEND DEP_LIBS ${ARC_DIR}/LogProject.${STATIC_LIB} ) MESSAGE(STATUS "Memory Project - Done") #### MemoryPool ----------------------------------- #
-
-
์คํ ์ฝ๋
void Example() { MemoryManager::GetHandle().Init(); MemoryManager::GetHandle().SetDefaultSize( 32 ); MemoryPtr<Object> Value = MemoryManager::GetHandle().Create<Object>( 10 ); MemoryManager::GetHandle().Delete<Object>( Value ); MemoryManager::GetHandle().Destroy(); }
-
๊ฒฐ๊ณผ ์ฝ์
17:59:40:528 | INFO OS | Windows 17:59:40:528 | WARN MemoryManager | struct Object | There isn't existed this type of MemoryPool 17:59:40:528 | INFO MemoryManager | struct Object | Create new pool ptr list 17:59:40:528 | INFO MemoryManager | struct Object | Pool Ptr 000001D709C9CD00 - Start Ptr 000001D709CA7400 | Create new memory pool **17:59:40:528 | INFO Instance | struct Object | 000001D709CA7400 | Create new 17:59:40:528 | INFO Instance | struct Object | 000001D709CA7400 | Delete**
-
์คํ ์ฝ๋
struct IObject { public : IObject( int Value ) : m_Value( Value ) {}; virtual ~IObject() {}; virtual void Action() { Log::Info("IObject"); } public : int m_Value; }; struct Object : public IObject { public : Object( int Value ) : IObject( Value ) {}; Object() : IObject( 0 ) {}; virtual ~Object() {}; virtual void Action() { Log::Info("Object"); } }; void Example() { MemoryManager::GetHandle().Init(); MemoryManager::GetHandle().SetDefaultSize( 32 ); MemoryPtr<IObject> IOValue = MemoryManager::GetHandle().Create<IObject>( 10 ); MemoryPtr<Object> OValue = IOValue; MemoryManager::GetHandle().Destroy(); }
-
๊ฒฐ๊ณผ ์ฝ์
18:01:32:826 | INFO OS | Windows 18:01:32:826 | WARN MemoryManager | struct IObject | There isn't existed this type of MemoryPool 18:01:32:826 | INFO MemoryManager | struct IObject | Create new pool ptr list 18:01:32:826 | INFO MemoryManager | struct IObject | Pool Ptr 000001F8DB371AE0 - Start Ptr 000001F8DB377140 | Create new memory pool 18:01:32:826 | INFO Instance | struct IObject | 000001F8DB377140 | Create new **18:01:32:826 | WARN MPTR | MemoryPtr<struct Object>::CheckValidityofCopy | struct Object | No inheritance relationship with struct IObject 18:01:32:826 | ERROR MPTR | MemoryPtr<struct Object>::operator = | struct Object | Copying this MPtr is invalid**
-
์คํ ์ฝ๋
void Example() { MemoryManager::GetHandle().Init(); MemoryManager::GetHandle().SetDefaultSize( 32 ); MemoryManager::GetHandle().Create<Object>( 11 ); MemoryPtr<Object> OValue = new Object( 10 ); MemoryManager::GetHandle().Delete<Object>( OValue ); MemoryManager::GetHandle().Destroy(); }
-
๊ฒฐ๊ณผ ์ฝ์
18:04:08:086 | INFO OS | Windows 18:04:08:086 | WARN MemoryManager | struct Object | There isn't existed this type of MemoryPool 18:04:08:086 | INFO MemoryManager | struct Object | Create new pool ptr list 18:04:08:086 | INFO MemoryManager | struct Object | Pool Ptr 000001D44E6B0EA0 - Start Ptr 000001D44E6B5410 | Create new memory pool 18:04:08:086 | INFO Instance | struct Object | 000001D44E6B5410 | Create new **18:04:08:086 | WARN MemoryManager | struct Object | There is no memory pool CCCCCCCCCCCCCCCC** 18:04:08:086 | INFO MemoryManager | Pool Ptr 000001D44E6B0EA0 - Start Ptr 000001D44E6B5410 | Destroy memory pool 18:04:08:086 | INFO Instance | struct Object | 000001D44E6B5410 | Delete
- MemoryManager๋ฅผ ํตํด์ ์์ฑ๋ MemoryPtr์ด ์๋ ๊ฒฝ์ฐ, Destruct ๋ถ๊ฐ
- Log Project์ Memory Project๋ฅผ ์งํํ๋ฉด์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค์ด์ ์ฌ์ฉํ ์ ์๋๋ก ํ๊ฒ ๋ค.
- ๋๋์ด์ ๊ด๋ฆฌํ๋ค๋ณด๋ ๋์ฑ ํธ๋ฆฌํ์๋ค. ์ค์ ๋ก ์ฌ์ฉ๊ฐ๋ฅํ ๋ฒ์ ผ๋ง์ ์ฌ์ฉํ๊ฒ ๋๋ค๋ฉด ๊ธฐ์กด์ ํ๋ก์ ํธ์์ ๋จ์ ๋ฒ์ ผ์ ์ฌ๋ ค์ฃผ๊ฑฐ๋ ๊ทธ๋๋ก ์ฌ์ฉ๋ง ํ๋ฉด ๋ค๋ฅธ ํ๋ก์ ํธ๋ค์๋ ํฌ๊ฒ ๋ฌด๋ฆฌ๊ฐ ์์๋ค.
- ๋ฌผ๋ก ์ธํฐํ์ด์ค๊ฐ 180๋ ๋ฐ๋๋ ๊ฒฝ์ฐ์๋ ํด๋น ํ๋ก์ ํธ์ ์์กดํ๋ ๋ค๋ฅธ ํ๋ก์ ํธ๋ค์ ์์ ๋ ํ์ํ๊ฒ ์ง๋ง, ์ธํฐํ์ด์ค๋ฅผ ์ ์งํ๋ฉฐ ํ์ฅํ ๊ฒฝ์ฐ์๋ ๊ทธ๋ด ํ์๊ฐ ๊ฑฐ์ ์์๋ค.
- ๋ํ, ์ ์ , ๋์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋น๋ํ๋ฉฐ ๋ง๋ค๊ณ ์ฌ์ฉํจ์ผ๋ก์จ, ๊ธฐ์กด์ ์์คํ์ผ๋ค์ ์ ์ฒด ์ถ๊ฐํ๋ ๋ฐฉ์๋ณด๋ค ํธ๋ฆฌํ์๋ค.
- Github์ Repository๋ฅผ ๋ถ๋ฌ์์ ๋น๋ํ๋ ๊ณผ์ ๋ค์ ๋ฃ์์ผ๋ก์จ, ๋จ์ํ ๋ด ํ๋ก์ ํธ๋ง์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ค๋ฅธ ์คํ ์์ค๋ค์ ์ฌ์ฉํจ์ ์์ด์๋ ์์ฉํ ์ ์๋ ์ ์ฉํ ๊ฒฝํ์ด์๋ค.
- MemoryManager์ IMemoryPool์ ๋ง๋ค๋ฉด์ ์ธํฐํ์ด์ค์ ์ค์์ฑ์ ์๊ฒ ๋์๋ค. template์ ๊ฒฝ์ฐ์๋ virtual ํจ์๋ก ์ค์ ํ ์๊ฐ ์๊ธฐ์, ํด๋น ๋ถ๋ถ์ ๊ตฌ์ฒดํ ํด๋์ค์์ ๊ตฌํ์ ํ๊ณ , ๋ค๋ฅธ ๊ธฐ๋ฅ๋ค์ ํฌ๊ด์ ์ธ ๊ธฐ๋ฅ๋ค์ ์ธํฐํ์ด์ค์ ๋ฃ์ด์ ๊ตฌํ์ ์งํํ์๋ค.
- MemoryPtr ๋ด์์์ dynamic_cast๋ฅผ ํตํด์ RTTI์ ๋ํด์ ์กฐ๊ธ ๋ ๊น๊ฒ ์๊ฒ ๋์๋ค. ์๋ฅผ ๋ค์ด, Parent ์ธ์คํด์ค๊ฐ ํ ๋น๋๊ณ ๊ทธ๊ฒ์ Parent๋ฅผ ์์๋ฐ๋ Child๋ก ์บ์คํ ํ ๊ฒฝ์ฐ, ์คํจํ๊ฒ ๋๋ค. ์๋ํ๋ฉด ํด๋น ์ธ์คํด์ค๋ Child์ ๋ํ v-table์ ์ง๋๊ณ ์์ง ์๊ธฐ ๋๋ฌธ์, ์ ํจํ์ง ์์ ์บ์คํ ์ด๋ผ๊ณ ํ๋จํ์ฌ dynamic_cast์ ๊ฒฐ๊ณผ๊ฐ์ผ๋ก nullptr์ด ๋์ค๊ธฐ ๋๋ฌธ์ด๋ค.
- MemoryManager์์ Create ๊ฒฐ๊ณผ ๊ฐ์ผ๋ก MemoryPtr์ ๋ฐํํ๊ฒ ๋๋๋ฐ, ์ด๋ ์์๊ฐ์ฒด์ ๊ฐ๋ ์ ๋ฐฐ์ฐ๊ณ ๋ ๋ค์๋ ๊ทธ๋ฌํ ๋ถํ์ํ ๊ฐ์ฒด์ ์์ฑ๊ณผ ์ฐ์ฐ๋์ ๋ง๊ธฐ ์ํด์ ์ด๋์์ฑ์์ ์ด๋ ๋ณต์ฌ ๋์ ์๋ฅผ MemoryPtr์ ๋ฃ์ด์ ๋ณด๋ค ํจ์จ์ ์ธ ์์ฑ์ด ๋ ์ ์๋๋ก ํ์๋ค.