Преглед изворни кода

Fix ProxyAllocator to track size of allocations, still can't decide how mush is deallocated

Daniele Bartolini пре 12 година
родитељ
комит
628d388aae
2 измењених фајлова са 15 додато и 3 уклоњено
  1. 9 0
      engine/core/mem/ProxyAllocator.cpp
  2. 6 3
      engine/core/mem/ProxyAllocator.h

+ 9 - 0
engine/core/mem/ProxyAllocator.cpp

@@ -38,6 +38,7 @@ static ProxyAllocator* g_proxy_allocators_head = NULL;
 ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 	m_allocator(allocator),
 	m_name(name),
+	m_total_allocated(0),
 	m_next(NULL)
 {
 	CE_ASSERT(name != NULL, "Name must be != NULL");
@@ -53,6 +54,8 @@ ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 //-----------------------------------------------------------------------------
 void* ProxyAllocator::allocate(size_t size, size_t align)
 {
+	m_total_allocated += size;
+
 	return m_allocator.allocate(size, align);
 }
 
@@ -62,6 +65,12 @@ void ProxyAllocator::deallocate(void* data)
 	m_allocator.deallocate(data);
 }
 
+//-----------------------------------------------------------------------------
+size_t ProxyAllocator::allocated_size()
+{
+	return m_total_allocated;
+}
+
 //-----------------------------------------------------------------------------
 const char* ProxyAllocator::name() const
 {

+ 6 - 3
engine/core/mem/ProxyAllocator.h

@@ -28,16 +28,15 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Memory.h"
+#include "Allocator.h"
 
 namespace crown
 {
 
-class Allocator;
-
 /// Offers the facility to tag allocators by a string identifier.
 /// Proxy allocator is appended to a global linked list when instantiated
 /// so that it is possible to later visit that list for debugging purposes.
-class ProxyAllocator
+class ProxyAllocator : public Allocator
 {
 public:
 
@@ -50,6 +49,9 @@ public:
 	/// @copydoc Allocator::deallocate()
 	void					deallocate(void* data);
 
+	/// @copydoc Allocator::allocated_size()
+	size_t					allocated_size();
+
 	/// Returns the name of the proxy allocator
 	const char*				name() const;
 
@@ -74,6 +76,7 @@ private:
 
 	Allocator&				m_allocator;
 	const char*				m_name;
+	size_t					m_total_allocated;
 
 	ProxyAllocator*			m_next;
 };