Revision: 1617
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1617&view=rev
Author:   rorthomas
Date:     2011-01-31 00:07:29 +0000 (Mon, 31 Jan 2011)

Log Message:
-----------
MemoryWrapper working now: tracking deallocations as well

Modified Paths:
--------------
    trunk/source/main/memoryWrapper.cpp
    trunk/source/main/memoryWrapper.h

Modified: trunk/source/main/memoryWrapper.cpp
===================================================================
--- trunk/source/main/memoryWrapper.cpp 2011-01-30 23:54:55 UTC (rev 1616)
+++ trunk/source/main/memoryWrapper.cpp 2011-01-31 00:07:29 UTC (rev 1617)
@@ -3,17 +3,25 @@
 
 unsigned long MemoryWrapper::memory_used = 0;
 
+std::map<void *, unsigned long> MemoryWrapper::allocations;
+
 void *MemoryWrapper::allocBytes(size_t count)
 {
        void* ptr = nedalloc::nedmalloc(count);
+
        memory_used += count;
+       allocations[ptr] = count;
+
        return ptr;
 }
 
 void *MemoryWrapper::callocBytes(size_t no, size_t size)
 {
        void* ptr = nedalloc::nedcalloc(no, size);
+
        memory_used += size;
+       allocations[ptr] = size;
+
        return ptr;
 }
 
@@ -22,6 +30,13 @@
        if(!ptr)
                return;
 
+       // get the memory size of this and substract it again
+       if(allocations.find(ptr) != allocations.end())
+       {
+               memory_used -= allocations[ptr];
+               allocations.erase(ptr);
+       }
+
        nedalloc::nedfree(ptr);
 }
 
@@ -31,6 +46,7 @@
        void* ptr = align ? nedalloc::nedmemalign(align, count) : 
nedalloc::nedmemalign(SIMD_ALIGNMENT, count);
 
        memory_used += count;
+       allocations[ptr] = count;
        
        return ptr;
 }
@@ -40,6 +56,13 @@
        if (!ptr)
                return;
 
+       // get the memory size of this and substract it again
+       if(allocations.find(ptr) != allocations.end())
+       {
+               memory_used -= allocations[ptr];
+               allocations.erase(ptr);
+       }
+
        nedalloc::nedfree(ptr);
 }
 

Modified: trunk/source/main/memoryWrapper.h
===================================================================
--- trunk/source/main/memoryWrapper.h   2011-01-30 23:54:55 UTC (rev 1616)
+++ trunk/source/main/memoryWrapper.h   2011-01-31 00:07:29 UTC (rev 1617)
@@ -7,10 +7,14 @@
 #define ror_calloc(x,y) MemoryWrapper::callocBytes(x,y)
 #define ror_free(x)     MemoryWrapper::deallocBytes(x)
 
+#include <map>
+
 class MemoryWrapper
 {
 protected:
+
        static unsigned long memory_used;
+       static std::map<void *, unsigned long> allocations;
 public:
        static void* allocBytes(size_t count);
        static void* callocBytes(size_t no, size_t size);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to