Explorar o código

Fix assert in align_top and comment out memory dumping util

Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
c4c8f8f365
Modificáronse 2 ficheiros con 18 adicións e 19 borrados
  1. 17 18
      engine/core/mem/Memory.h
  2. 1 1
      engine/tests/allocators.cpp

+ 17 - 18
engine/core/mem/Memory.h

@@ -28,7 +28,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Assert.h"
-#include "OS.h"
 
 namespace crown
 {
@@ -41,8 +40,8 @@ const size_t	DEFAULT_ALIGN	= 4;			//!< Default memory alignment in bytes
 /// Returns the pointer @a p aligned to the desired @a align byte
 inline void* align_top(void* p, size_t align)
 {
-	CE_ASSERT(align > 1, "Alignment must be > 1");
-	CE_ASSERT(align % 2 == 0, "Alignment must be a power of two");
+	CE_ASSERT(align >= 1, "Alignment must be > 1");
+	CE_ASSERT(align % 2 == 0 || align == 1, "Alignment must be a power of two");
 
 	uintptr_t ptr = (uintptr_t)p;
 
@@ -56,24 +55,24 @@ inline void* align_top(void* p, size_t align)
 	return (void*) ptr;
 }
 
-/// Dumps the memory content pointed by @a p
-inline void dump(void* p, size_t size, size_t word_size)
-{
-	uint8_t* mem = (uint8_t*) p;
+// /// Dumps the memory content pointed by @a p
+// inline void dump(void* p, size_t size, size_t word_size)
+// {
+// 	uint8_t* mem = (uint8_t*) p;
 
-	for (size_t i = 0; i < size; i++, mem++)
-	{
-		if (i % word_size == 0)
-		{
-			os::printf("\n");
-			os::printf("[.. %.4X] ", (size_t)mem);
-		}
+// 	for (size_t i = 0; i < size; i++, mem++)
+// 	{
+// 		if (i % word_size == 0)
+// 		{
+// 			os::printf("\n");
+// 			os::printf("[.. %.4X] ", (size_t)mem);
+// 		}
 
-		os::printf("%.2X ", *mem);
-	}
+// 		os::printf("%.2X ", *mem);
+// 	}
 
-	os::printf("\n");
-}
+// 	os::printf("\n");
+// }
 
 #ifdef _MSC_VER
 	#define CE_ALIGNOF(x) __alignof(x)

+ 1 - 1
engine/tests/allocators.cpp

@@ -27,6 +27,6 @@ int main()
 	stack.allocate(12);
 	stack.allocate(5);
 
-	memory::dump(buffer, stack.allocated_size(), 4);
+	//memory::dump(buffer, stack.allocated_size(), 4);
 }