Initial commit
[com/gs-lite.git] / src / lib / gscpaux / block_allocator.h
diff --git a/src/lib/gscpaux/block_allocator.h b/src/lib/gscpaux/block_allocator.h
new file mode 100644 (file)
index 0000000..ae9fc4f
--- /dev/null
@@ -0,0 +1,37 @@
+// Distributed under the MIT license. Copyright (c) 2010, Ivan Vashchaev
+
+#ifndef BLOCK_ALLOCATOR_H
+#define BLOCK_ALLOCATOR_H
+
+class block_allocator
+{
+private:
+       struct block
+       {
+               size_t size;
+               size_t used;
+               char *buffer;
+               block *next;
+       };
+
+       block *m_head;
+       size_t m_blocksize;
+
+       block_allocator(const block_allocator &);
+       block_allocator &operator=(block_allocator &);
+
+public:
+       block_allocator(size_t blocksize);
+       ~block_allocator();
+
+       // exchange contents with rhs
+       void swap(block_allocator &rhs);
+
+       // allocate memory
+       void *malloc(size_t size);
+
+       // free all allocated blocks
+       void free();
+};
+
+#endif