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()
36 unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
38 if (nFileLen <= m_nMemSize)
40 nAllocatedSize = nFileLen;
44 unsigned int nTargetSize;
45 if (nFileLen < m_nMemMax)
46 nTargetSize = nFileLen;
48 nTargetSize = m_nMemMax;
50 // Free existing memory
58 // Allocate new memory
59 //printf("allocating %u bytes memory\n", nTargetSize);
60 // m_pMem = new unsigned char[nTargetSize];
61 m_pMem = new (nothrow) unsigned char[nTargetSize];
62 while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 )
64 nTargetSize -= 16 * 1024 * 1024;
65 m_pMem = new (nothrow) unsigned char[nTargetSize];
69 m_nMemSize = nTargetSize;
70 nAllocatedSize = nTargetSize;