2 RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
4 Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
7 #include "MemoryPool.h"
10 CMemoryPool::CMemoryPool()
15 unsigned int nAvailPhys = GetAvailPhysMemorySize();
16 if (nAvailPhys < 16 * 1024 * 1024)
18 nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize()
20 if (nAvailPhys < 16 * 1024 * 1024)
21 m_nMemMax = nAvailPhys / 2; // Leave some memory for CChainWalkSet
23 m_nMemMax = nAvailPhys - 8 * 1024 * 1024; // Leave some memory for CChainWalkSet
26 CMemoryPool::~CMemoryPool()
30 printf("Freeing %i bytes of memory\n", m_nMemSize);
38 unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
40 if (nFileLen <= m_nMemSize) {
41 nAllocatedSize = nFileLen;
45 unsigned int nTargetSize;
46 if (nFileLen < m_nMemMax) {
47 nTargetSize = nFileLen;
50 nTargetSize = m_nMemMax;
52 // Free existing memory
55 printf("Freeing %i bytes of memory\n", m_nMemSize);
62 // Allocate new memory
63 //printf("allocating %u bytes memory\n", nTargetSize);
64 // m_pMem = new unsigned char[nTargetSize];
66 printf("Allocating %i bytes of memory - ", nTargetSize);
69 m_pMem = new (nothrow) unsigned char[nTargetSize];
70 while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) {
73 printf("Allocating %i bytes of memory (backup) - ", nTargetSize);
75 nTargetSize -= 16 * 1024 * 1024;
76 m_pMem = new (nothrow) unsigned char[nTargetSize];
82 m_nMemSize = nTargetSize;
83 nAllocatedSize = nTargetSize;