Daniele Bartolini пре 12 година
родитељ
комит
5482b08eec
4 измењених фајлова са 111 додато и 0 уклоњено
  1. 2 0
      src/CMakeLists.txt
  2. 1 0
      src/Crown.h
  3. 52 0
      src/core/mem/ProxyAllocator.cpp
  4. 56 0
      src/core/mem/ProxyAllocator.h

+ 2 - 0
src/CMakeLists.txt

@@ -153,12 +153,14 @@ set (STRINGS_HEADERS
 
 
 set (MEM_SRC
 set (MEM_SRC
 	core/mem/MallocAllocator.cpp
 	core/mem/MallocAllocator.cpp
+	core/mem/ProxyAllocator.cpp
 )
 )
 
 
 set (MEM_HEADERS
 set (MEM_HEADERS
 	core/mem/Memory.h
 	core/mem/Memory.h
 	core/mem/Allocator.h
 	core/mem/Allocator.h
 	core/mem/MallocAllocator.h
 	core/mem/MallocAllocator.h
+	core/mem/ProxyAllocator.h
 )
 )
 
 
 set (COMPRESSORS_SRC
 set (COMPRESSORS_SRC

+ 1 - 0
src/Crown.h

@@ -71,6 +71,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Memory.h"
 #include "Memory.h"
 #include "Allocator.h"
 #include "Allocator.h"
 #include "MallocAllocator.h"
 #include "MallocAllocator.h"
+#include "ProxyAllocator.h"
 
 
 // Core/Streams
 // Core/Streams
 #include "Stream.h"
 #include "Stream.h"

+ 52 - 0
src/core/mem/ProxyAllocator.cpp

@@ -0,0 +1,52 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "ProxyAllocator.h"
+#include "Allocator.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+ProxyAllocator::ProxyAllocator(Allocator& allocator, const char* name) :
+	m_allocator(allocator),
+	m_name(name)
+{
+	assert(name != NULL);
+}
+
+//-----------------------------------------------------------------------------
+void* ProxyAllocator::allocate(size_t size, size_t align)
+{
+	return m_allocator.allocate(size, align);
+}
+
+//-----------------------------------------------------------------------------
+void ProxyAllocator::deallocate(void* data)
+{
+	m_allocator.deallocate(data);
+}
+
+} // namespace crown

+ 56 - 0
src/core/mem/ProxyAllocator.h

@@ -0,0 +1,56 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "Types.h"
+#include "Memory.h"
+
+namespace crown
+{
+
+class Allocator;
+
+/// Offers the facility to tag allocations by a string identifier.
+class ProxyAllocator
+{
+public:
+
+	/// Tag all allocations made with @allocator by the given @name
+					ProxyAllocator(Allocator& allocator, const char* name);
+
+	/// @copydoc Allocator::allocate()
+	void*			allocate(size_t size, size_t align = memory::DEFAULT_ALIGN);
+
+	/// @copydoc Allocator::deallocate()
+	void			deallocate(void* data);
+
+private:
+
+	Allocator&		m_allocator;
+	const char*		m_name;
+};
+
+} // namespace crown