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(unsigned int bytesForChainWalkSet)
15 unsigned int nAvailPhys = GetAvailPhysMemorySize();
16 if (nAvailPhys < 32 * 1024 * 1024)
18 nAvailPhys = 256 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize())
21 m_nMemMax = nAvailPhys - bytesForChainWalkSet; // Leave memory for CChainWalkSet
23 if (m_nMemMax < 16 * 1024 * 1024)
24 m_nMemMax = 16 * 1024 * 1024;
28 CMemoryPool::~CMemoryPool()
38 unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize)
40 if (nFileLen <= m_nMemSize)
42 nAllocatedSize = nFileLen;
46 unsigned int nTargetSize;
47 if (nFileLen < m_nMemMax)
48 nTargetSize = nFileLen;
50 nTargetSize = m_nMemMax;
52 // Free existing memory
60 // Allocate new memory
61 //printf("allocating %u bytes memory\n", nTargetSize);
62 m_pMem = new (nothrow) unsigned char[nTargetSize];
63 while (m_pMem == NULL && nTargetSize >= 32 * 1024 * 1024 )
65 nTargetSize -= 16 * 1024 * 1024;
66 m_pMem = new (nothrow) unsigned char[nTargetSize];
71 m_nMemSize = nTargetSize;
72 nAllocatedSize = nTargetSize;