X-Git-Url: https://git.sesse.net/?p=freerainbowtables;a=blobdiff_plain;f=Client%20Applications%2Frcracki_mt%2FMemoryPool.cpp;fp=Client%20Applications%2Frcracki_mt%2FMemoryPool.cpp;h=77a4eabbd5aacca9bdd22776718c896ad7952084;hp=10e235c4b8485e4b4883d3571fd13c9c0358c4ad;hb=86bbf0fd5ba4e07d3279b4179fd8fc808198eaae;hpb=3d42602c1f746b5768f0e6c9d22884a9806eadc0 diff --git a/Client Applications/rcracki_mt/MemoryPool.cpp b/Client Applications/rcracki_mt/MemoryPool.cpp index 10e235c..77a4eab 100644 --- a/Client Applications/rcracki_mt/MemoryPool.cpp +++ b/Client Applications/rcracki_mt/MemoryPool.cpp @@ -1,110 +1,110 @@ -/* - * rcracki_mt is a multithreaded implementation and fork of the original - * RainbowCrack - * - * Copyright (C) Zhu Shuanglei - * Copyright Martin Westergaard Jørgensen - * Copyright 2009, 2010 Daniël Niggebrugge - * Copyright 2009, 2010 James Nobis - * Copyright 2010 uroskn - * - * This file is part of rcracki_mt. - * - * rcracki_mt is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * rcracki_mt is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with rcracki_mt. If not, see . - */ - -#include "MemoryPool.h" -#include "Public.h" - -CMemoryPool::CMemoryPool(unsigned int bytesSaved, bool bDebug, uint64 maxMem) -{ - m_pMem = NULL; - m_nMemSize = 0; - debug = bDebug; - - uint64 nAvailPhys = GetAvailPhysMemorySize(); - - if ( debug ) - { - #ifdef _WIN32 - printf( "Debug: nAvailPhys: %I64u\n", nAvailPhys ); - #else - printf( "Debug: nAvailPhys: %llu\n", nAvailPhys ); - #endif - printf( "Debug: bytesSaved: %d\n", bytesSaved ); - } - - if ( maxMem > 0 && maxMem < nAvailPhys ) - nAvailPhys = maxMem; - - m_nMemMax = nAvailPhys - bytesSaved; // Leave memory for CChainWalkSet - - if (m_nMemMax < 16 * 1024 * 1024) - m_nMemMax = 16 * 1024 * 1024; -} - -CMemoryPool::~CMemoryPool() -{ - if (m_pMem != NULL) - { - delete [] m_pMem; - m_pMem = NULL; - m_nMemSize = 0; - } -} - -unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, uint64& nAllocatedSize) -{ - if (nFileLen <= m_nMemSize) - { - nAllocatedSize = nFileLen; - return m_pMem; - } - - unsigned int nTargetSize; - if (nFileLen < m_nMemMax) - nTargetSize = nFileLen; - else - nTargetSize = m_nMemMax; - - // Free existing memory - if (m_pMem != NULL) - { - delete [] m_pMem; - m_pMem = NULL; - m_nMemSize = 0; - } - - // Allocate new memory - //printf("allocating %u bytes memory\n", nTargetSize); - m_pMem = new (nothrow) unsigned char[nTargetSize]; - while (m_pMem == NULL && nTargetSize >= 32 * 1024 * 1024 ) - { - nTargetSize -= 16 * 1024 * 1024; - m_pMem = new (nothrow) unsigned char[nTargetSize]; - } - - if (m_pMem != NULL) - { - m_nMemSize = nTargetSize; - nAllocatedSize = nTargetSize; - return m_pMem; - } - else - { - m_nMemSize = 0; - nAllocatedSize = 0; - return NULL; - } -} +/* + * rcracki_mt is a multithreaded implementation and fork of the original + * RainbowCrack + * + * Copyright (C) Zhu Shuanglei + * Copyright Martin Westergaard Jørgensen + * Copyright 2009, 2010 Daniël Niggebrugge + * Copyright 2009, 2010 James Nobis + * Copyright 2010 uroskn + * + * This file is part of rcracki_mt. + * + * rcracki_mt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * rcracki_mt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with rcracki_mt. If not, see . + */ + +#include "MemoryPool.h" +#include "Public.h" + +CMemoryPool::CMemoryPool(unsigned int bytesSaved, bool bDebug, uint64 maxMem) +{ + m_pMem = NULL; + m_nMemSize = 0; + debug = bDebug; + + unsigned long nAvailPhys = GetAvailPhysMemorySize(); + + if ( debug ) + { + #if defined(_WIN32) && !defined(__GNUC__) + printf( "Debug: nAvailPhys: %I64u\n", nAvailPhys ); + #else + printf( "Debug: nAvailPhys: %lu\n", nAvailPhys ); + #endif + printf( "Debug: bytesSaved: %d\n", bytesSaved ); + } + + if ( maxMem > 0 && maxMem < nAvailPhys ) + nAvailPhys = maxMem; + + m_nMemMax = nAvailPhys - bytesSaved; // Leave memory for CChainWalkSet + + if (m_nMemMax < 16 * 1024 * 1024) + m_nMemMax = 16 * 1024 * 1024; +} + +CMemoryPool::~CMemoryPool() +{ + if (m_pMem != NULL) + { + delete [] m_pMem; + m_pMem = NULL; + m_nMemSize = 0; + } +} + +unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, uint64& nAllocatedSize) +{ + if (nFileLen <= m_nMemSize) + { + nAllocatedSize = nFileLen; + return m_pMem; + } + + unsigned int nTargetSize; + if (nFileLen < m_nMemMax) + nTargetSize = nFileLen; + else + nTargetSize = m_nMemMax; + + // Free existing memory + if (m_pMem != NULL) + { + delete [] m_pMem; + m_pMem = NULL; + m_nMemSize = 0; + } + + // Allocate new memory + //printf("allocating %u bytes memory\n", nTargetSize); + m_pMem = new (nothrow) unsigned char[nTargetSize]; + while (m_pMem == NULL && nTargetSize >= 32 * 1024 * 1024 ) + { + nTargetSize -= 16 * 1024 * 1024; + m_pMem = new (nothrow) unsigned char[nTargetSize]; + } + + if (m_pMem != NULL) + { + m_nMemSize = nTargetSize; + nAllocatedSize = nTargetSize; + return m_pMem; + } + else + { + m_nMemSize = 0; + nAllocatedSize = 0; + return NULL; + } +}