X-Git-Url: https://git.sesse.net/?p=freerainbowtables;a=blobdiff_plain;f=Common%2Frt%20api%2FMemoryPool.cpp;h=a6745073f0e97e9953c510280ac32b405106de2f;hp=053db7a04b5fff229fe08a321768693291e7f9b9;hb=86bbf0fd5ba4e07d3279b4179fd8fc808198eaae;hpb=0fb676244827a448dc60118d6558c4a4e346ffee diff --git a/Common/rt api/MemoryPool.cpp b/Common/rt api/MemoryPool.cpp index 053db7a..a674507 100644 --- a/Common/rt api/MemoryPool.cpp +++ b/Common/rt api/MemoryPool.cpp @@ -45,8 +45,10 @@ CMemoryPool::CMemoryPool() CMemoryPool::~CMemoryPool() { - if (m_pMem != NULL) - { + if (m_pMem != NULL) { +#ifdef _MEMORYDEBUG + printf("Freeing %i bytes of memory\n", m_nMemSize); +#endif delete [] m_pMem; m_pMem = NULL; m_nMemSize = 0; @@ -55,21 +57,23 @@ CMemoryPool::~CMemoryPool() unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize) { - if (nFileLen <= m_nMemSize) - { + if (nFileLen <= m_nMemSize) { nAllocatedSize = nFileLen; return m_pMem; } unsigned int nTargetSize; - if (nFileLen < m_nMemMax) + if (nFileLen < m_nMemMax) { nTargetSize = nFileLen; - else + } + else { nTargetSize = m_nMemMax; - + } // Free existing memory - if (m_pMem != NULL) - { + if (m_pMem != NULL) { +#ifdef _MEMORYDEBUG + printf("Freeing %i bytes of memory\n", m_nMemSize); +#endif delete [] m_pMem; m_pMem = NULL; m_nMemSize = 0; @@ -77,22 +81,29 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc // Allocate new memory //printf("allocating %u bytes memory\n", nTargetSize); + // m_pMem = new unsigned char[nTargetSize]; +#ifdef _MEMORYDEBUG + printf("Allocating %i bytes of memory - ", nTargetSize); +#endif + m_pMem = new (nothrow) unsigned char[nTargetSize]; - while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) - { - nTargetSize -= 16 * 1024 * 1024; - m_pMem = new (nothrow) unsigned char[nTargetSize]; + while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) { +#ifdef _MEMORYDEBUG + printf("failed!\n"); + printf("Allocating %i bytes of memory (backup) - ", nTargetSize); +#endif + nTargetSize -= 16 * 1024 * 1024; + m_pMem = new (nothrow) unsigned char[nTargetSize]; } - - if (m_pMem != NULL) - { + if (m_pMem != NULL) { +#ifdef _MEMORYDEBUG + printf("success!\n"); +#endif m_nMemSize = nTargetSize; nAllocatedSize = nTargetSize; return m_pMem; } - else - { - m_nMemSize = 0; + else { nAllocatedSize = 0; return NULL; }