X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=Common%2Frt%20api%2FMemoryPool.cpp;h=bde4ed0e10635e1b86b7d5b6f2be2613c10e92fd;hb=47c71901e7a97c226c8f1df749e3606d43656f32;hp=4c8d5c98eeb810e7d06ac81ad017bf8ef12d5e61;hpb=08366be03fa6160b831222667a0c7f6df831f0d8;p=freerainbowtables diff --git a/Common/rt api/MemoryPool.cpp b/Common/rt api/MemoryPool.cpp index 4c8d5c9..bde4ed0 100644 --- a/Common/rt api/MemoryPool.cpp +++ b/Common/rt api/MemoryPool.cpp @@ -1,8 +1,28 @@ /* - RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique. - - Copyright (C) Zhu Shuanglei -*/ + * freerainbowtables is a project for generating, distributing, and using + * perfect rainbow tables + * + * Copyright (C) Zhu Shuanglei + * Copyright Martin Westergaard Jørgensen + * Copyright 2009, 2010 Daniël Niggebrugge + * Copyright 2009, 2010, 2011 James Nobis + * Copyright 2010 uroskn + * + * This file is part of freerainbowtables. + * + * freerainbowtables 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. + * + * freerainbowtables 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 freerainbowtables. If not, see . + */ #include "MemoryPool.h" #include "Public.h" @@ -12,7 +32,7 @@ CMemoryPool::CMemoryPool() m_pMem = NULL; m_nMemSize = 0; - unsigned int nAvailPhys = GetAvailPhysMemorySize(); + unsigned long nAvailPhys = GetAvailPhysMemorySize(); if (nAvailPhys < 16 * 1024 * 1024) { nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize() @@ -25,57 +45,61 @@ 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; + delete [] m_pMem; m_pMem = NULL; m_nMemSize = 0; } } -unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize) +unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, uint64& 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; + delete [] m_pMem; m_pMem = NULL; m_nMemSize = 0; } // 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 ) { + 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]; + 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 @@ -83,7 +107,9 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc nAllocatedSize = nTargetSize; return m_pMem; } - else { + else + { + m_nMemSize = 0; nAllocatedSize = 0; return NULL; }