]> git.sesse.net Git - freerainbowtables/blobdiff - Common/rt api/MemoryPool.cpp
(C)
[freerainbowtables] / Common / rt api / MemoryPool.cpp
index 053db7a04b5fff229fe08a321768693291e7f9b9..bde4ed0e10635e1b86b7d5b6f2be2613c10e92fd 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
  * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
  * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
- * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
+ * Copyright 2009, 2010, 2011 James Nobis <frt@quelrod.net>
  * Copyright 2010 uroskn
  *
  * This file is part of freerainbowtables.
@@ -32,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()
@@ -47,13 +47,16 @@ CMemoryPool::~CMemoryPool()
 {
        if (m_pMem != NULL)
        {
+#ifdef _MEMORYDEBUG
+               printf("Freeing %i bytes of memory\n", m_nMemSize);
+#endif 
                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)
        {
@@ -70,6 +73,9 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc
        // Free existing memory
        if (m_pMem != NULL)
        {
+#ifdef _MEMORYDEBUG
+               printf("Freeing %i bytes of memory\n", m_nMemSize);
+#endif 
                delete [] m_pMem;
                m_pMem = NULL;
                m_nMemSize = 0;
@@ -77,15 +83,26 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc
 
        // Allocate new memory
        //printf("allocating %u bytes memory\n", 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 )
        {
+#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];
        }
 
        if (m_pMem != NULL)
        {
+#ifdef _MEMORYDEBUG
+               printf("success!\n");
+#endif
                m_nMemSize = nTargetSize;
                nAllocatedSize = nTargetSize;
                return m_pMem;