summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2010-03-10 20:11:06 +0200
committerTimo Teras <timo.teras@iki.fi>2010-03-10 20:11:06 +0200
commit0183e33d9a4759764716e771b85e19f7a997b8bd (patch)
tree7921b52421171899d9df3999625b0f7134148350 /include
parentdc34e87746f69994aad893b39ee4cd3dda6e2f7b (diff)
downloadlibtf-0183e33d9a4759764716e771b85e19f7a997b8bd.tar.bz2
libtf-0183e33d9a4759764716e771b85e19f7a997b8bd.tar.xz
mem: add mmap allocator
use it for heaps and fiber stacks.
Diffstat (limited to 'include')
-rw-r--r--include/libtf/heap.h3
-rw-r--r--include/libtf/memory.h22
2 files changed, 24 insertions, 1 deletions
diff --git a/include/libtf/heap.h b/include/libtf/heap.h
index 3a16159..72c675a 100644
--- a/include/libtf/heap.h
+++ b/include/libtf/heap.h
@@ -14,6 +14,7 @@
#define TF_HEAP_H
#include <libtf/defines.h>
+#include <libtf/memory.h>
#define TF_HEAP_D 4
#define TF_HEAP_ITEM0 (TF_HEAP_D - 1)
@@ -78,7 +79,7 @@ static inline
void tf_heap_destroy(struct tf_heap_head *head)
{
if (head->item)
- free(head->item);
+ tf_bmem_free(head->item, head->allocated * sizeof(struct tf_heap_child));
head->item = NULL;
head->num_items = 0;
head->allocated = 0;
diff --git a/include/libtf/memory.h b/include/libtf/memory.h
new file mode 100644
index 0000000..04c2242
--- /dev/null
+++ b/include/libtf/memory.h
@@ -0,0 +1,22 @@
+/* memory.h - libtf memory allocator
+ *
+ * Copyright (C) 2009-2010 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 or later as
+ * published by the Free Software Foundation.
+ *
+ * See http://www.gnu.org/ for details.
+ */
+
+#ifndef TF_MEMORY_H
+#define TF_MEMORY_H
+
+/* Big/bulk memory allocation using mmap() or similar */
+void *tf_bmem_alloc(size_t size);
+void *tf_bmem_resize(void *ptr, size_t oldsize, size_t newsize);
+void tf_bmem_free(void *ptr, size_t size);
+
+#endif
+