Browse Source

Allocator stuff

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
74a54b7cfd

+ 1 - 1
include/anki/scene/SkinNode.h

@@ -123,7 +123,7 @@ public:
 	/// @}
 
 private:
-	PtrVector<SkinMesh> skinMeshes;
+	Vector<SkinMesh*> skinMeshes;
 	const ModelPatch* mpatch;
 	Vector<Vao> xfbVaos; ///< Used as a source VAO in XFB
 };

+ 6 - 0
include/anki/util/Allocator.h

@@ -347,6 +347,12 @@ public:
 		mpool->reset();
 	}
 
+	const StackMemoryPool& getMemoryPool() const
+	{
+		ANKI_ASSERT(mpool != nullptr);
+		return *mpool;
+	}
+
 private:
 	std::shared_ptr<StackMemoryPool> mpool;
 };

+ 3 - 1
include/anki/util/Memory.h

@@ -32,12 +32,14 @@ public:
 	/// Move
 	StackMemoryPool& operator=(StackMemoryPool&& other);
 
-	/// Access the max size
+	/// Access the total size
 	PtrSize getSize() const
 	{
 		return memsize;
 	}
 
+	PtrSize getAllocatedSize() const;
+
 	/// Allocate memory
 	void* allocate(PtrSize size) throw();
 

+ 9 - 0
src/scene/SkinNode.cpp

@@ -47,6 +47,15 @@ void SkinMesh::getVboInfo(const VertexAttribute attrib, const Vbo*& v,
 // SkinModelPatch                                                              =
 //==============================================================================
 
+//==============================================================================
+SkinModelPatch::~SkinModelPatch()
+{
+	for(SkinMesh* x : skinMeshes)
+	{
+		delete x;
+	}
+}
+
 //==============================================================================
 SkinModelPatch::SkinModelPatch(const ModelPatch* mpatch_)
 	: mpatch(mpatch_)

+ 8 - 0
src/util/Memory.cpp

@@ -52,10 +52,18 @@ StackMemoryPool& StackMemoryPool::operator=(StackMemoryPool&& other)
 	alignmentBits = other.alignmentBits;
 
 	other.memory = nullptr;
+	other.memsize = 0;
+	other.top = nullptr;
 
 	return *this;
 }
 
+//==============================================================================
+PtrSize StackMemoryPool::getAllocatedSize() const
+{
+	return top.load() - memory;
+}
+
 //==============================================================================
 void* StackMemoryPool::allocate(PtrSize size_) throw()
 {

+ 5 - 1
tests/Main.cpp

@@ -47,5 +47,9 @@ int main(int argc, char** argv)
 	ANKI_CONNECT(&LoggerSingleton::get(), messageRecieved, 
 		&msgh, handleLoggerMessages);
 
-	return TesterSingleton::get().run(argc, argv);
+	int exitcode = getTesterSingleton().run(argc, argv);
+
+	deleteTesterSingleton();
+
+	return exitcode;
 }

+ 16 - 0
tests/framework/Framework.cpp

@@ -199,4 +199,20 @@ int Tester::listTests()
 	return 0;
 }
 
+//==============================================================================
+static Tester* testerInstance = nullptr;
+
+Tester& getTesterSingleton()
+{
+	return *(testerInstance ? testerInstance : (testerInstance = new Tester));
+}
+
+void deleteTesterSingleton()
+{
+	if(testerInstance != nullptr)
+	{
+		delete testerInstance;
+	}
+}
+
 } // end namespace anki

+ 5 - 2
tests/framework/Framework.h

@@ -50,7 +50,10 @@ struct Tester
 };
 
 /// Singleton so we can do the ANKI_TEST trick
-typedef Singleton<Tester> TesterSingleton;
+extern Tester& getTesterSingleton();
+
+/// Delete the instance to make valgrind a bit happy
+extern void deleteTesterSingleton();
 
 //==============================================================================
 // Macros
@@ -63,7 +66,7 @@ typedef Singleton<Tester> TesterSingleton;
 	\
 	struct Foo##suiteName_##name_ { \
 		Foo##suiteName_##name_() { \
-			TesterSingleton::get().addTest(#name_, #suiteName_, \
+			getTesterSingleton().addTest(#name_, #suiteName_, \
 				test_##suiteName_##name_); \
 		} \
 	}; \

+ 2 - 2
tests/util/DynamicArray.cpp

@@ -22,7 +22,7 @@ ANKI_TEST(DynamicArray, Test)
 	arr.clear();
 
 	ANKI_TEST_EXPECT_EQ(arr.getSize(), 0);
-	ANKI_TEST_EXPECT_EQ(alloc.dump(), true);
+	ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(), 0);
 
 	// Again
 	arr.resize(n);
@@ -38,5 +38,5 @@ ANKI_TEST(DynamicArray, Test)
 	arr.clear();
 
 	ANKI_TEST_EXPECT_EQ(arr.getSize(), 0);
-	ANKI_TEST_EXPECT_EQ(alloc.dump(), true);
+	ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(), 0);
 }