[llvm-commits] CVS: poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp PoolAllocator.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Nov 1 21:28:20 PST 2004
Changes in directory poolalloc/runtime/FL2Allocator:
FreeListAllocator.cpp updated: 1.12 -> 1.13
PoolAllocator.h updated: 1.7 -> 1.8
---
Log message:
We can't really support this API in this allocator, but lets just pretend
we can for fun, it might come in handy in the future.
---
Diffs of the changes: (+33 -0)
Index: poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp
diff -u poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.12 poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.13
--- poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.12 Mon Nov 1 16:17:08 2004
+++ poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp Mon Nov 1 23:28:10 2004
@@ -322,3 +322,29 @@
LAH->Next->Prev = LAH->Prev;
free(LAH);
}
+
+unsigned poolobjsize(PoolTy *Pool, void *Node) {
+ if (Node == 0) return 0;
+
+ // If a null pool descriptor is passed in, this is not a pool allocated data
+ // structure. We don't really have any way to service this!!
+ if (Pool == 0) {
+ fprintf(stderr, "ERROR: Cannot call poolobjsize on a pool that is getting"
+ " memory from the heap. Sorry!\n");
+ abort();
+ }
+
+ // Check to see how many elements were allocated to this node...
+ FreedNodeHeader *FNH = (FreedNodeHeader*)((char*)Node-sizeof(NodeHeader));
+ assert((FNH->Header.Size & 1) && "Node not allocated!");
+ if (Size != ~1U) return FNH->Header.Size & ~1;
+
+ // Otherwise, we have a large array.
+ //LargeArrayHeader *LAH = ((LargeArrayHeader*)Node)-1;
+
+ // Note that we don't have a size for this object either, because we got it
+ // from malloc. :(
+ fprintf(stderr, "ERROR: Cannot call poolobjsize on a large array object. "
+ "Sorry!\n");
+ abort();
+}
Index: poolalloc/runtime/FL2Allocator/PoolAllocator.h
diff -u poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.7 poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.8
--- poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.7 Mon Nov 1 16:19:13 2004
+++ poolalloc/runtime/FL2Allocator/PoolAllocator.h Mon Nov 1 23:28:10 2004
@@ -93,6 +93,13 @@
void pooldestroy(PoolTy *Pool);
void *poolalloc(PoolTy *Pool, unsigned NumBytes);
void poolfree(PoolTy *Pool, void *Node);
+
+ /// poolobjsize - Reutrn the size of the object at the specified address, in
+ /// the specified pool. Note that this cannot be used in normal cases, as it
+ /// is completely broken if things land in the system heap. Perhaps in the
+ /// future. :(
+ ///
+ unsigned poolobjsize(PoolTy *Pool, void *Node);
}
#endif
More information about the llvm-commits
mailing list