فهرست منبع

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) :
 ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 	m_allocator(allocator),
 	m_allocator(allocator),
 	m_name(name),
 	m_name(name),
+	m_total_allocated(0),
 	m_next(NULL)
 	m_next(NULL)
 {
 {
 	CE_ASSERT(name != NULL, "Name must be != 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)
 void* ProxyAllocator::allocate(size_t size, size_t align)
 {
 {
+	m_total_allocated += size;
+
 	return m_allocator.allocate(size, align);
 	return m_allocator.allocate(size, align);
 }
 }
 
 
@@ -62,6 +65,12 @@ void ProxyAllocator::deallocate(void* data)
 	m_allocator.deallocate(data);
 	m_allocator.deallocate(data);
 }
 }
 
 
+//-----------------------------------------------------------------------------
+size_t ProxyAllocator::allocated_size()
+{
+	return m_total_allocated;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 const char* ProxyAllocator::name() const
 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 "Types.h"
 #include "Memory.h"
 #include "Memory.h"
+#include "Allocator.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-class Allocator;
-
 /// Offers the facility to tag allocators by a string identifier.
 /// Offers the facility to tag allocators by a string identifier.
 /// Proxy allocator is appended to a global linked list when instantiated
 /// Proxy allocator is appended to a global linked list when instantiated
 /// so that it is possible to later visit that list for debugging purposes.
 /// so that it is possible to later visit that list for debugging purposes.
-class ProxyAllocator
+class ProxyAllocator : public Allocator
 {
 {
 public:
 public:
 
 
@@ -50,6 +49,9 @@ public:
 	/// @copydoc Allocator::deallocate()
 	/// @copydoc Allocator::deallocate()
 	void					deallocate(void* data);
 	void					deallocate(void* data);
 
 
+	/// @copydoc Allocator::allocated_size()
+	size_t					allocated_size();
+
 	/// Returns the name of the proxy allocator
 	/// Returns the name of the proxy allocator
 	const char*				name() const;
 	const char*				name() const;
 
 
@@ -74,6 +76,7 @@ private:
 
 
 	Allocator&				m_allocator;
 	Allocator&				m_allocator;
 	const char*				m_name;
 	const char*				m_name;
+	size_t					m_total_allocated;
 
 
 	ProxyAllocator*			m_next;
 	ProxyAllocator*			m_next;
 };
 };