[llvm-commits] CVS: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
John Criswell
criswell at cs.uiuc.edu
Thu Nov 13 11:47:02 PST 2003
Changes in directory poolalloc/runtime/FreeListAllocator:
PoolAllocator.cpp updated: 1.14 -> 1.15
---
Log message:
Modified the code so that poolalloc() calls poolallocarray() if the
requested number of bytes is too small.
Minor commenting added.
---
Diffs of the changes: (+33 -4)
Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.14 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.15
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.14 Thu Nov 13 11:33:30 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp Thu Nov 13 11:46:00 2003
@@ -168,9 +168,20 @@
//
//===----------------------------------------------------------------------===//
-// poolinit - Initialize a pool descriptor to empty
//
-void poolinit(PoolTy *Pool, unsigned int NodeSize)
+// Function: poolinit ()
+//
+// Description:
+// Initialize a pool descriptor for a new pool.
+//
+// Inputs:
+// NodeSize - The typical size allocated for this pool.
+//
+// Outputs:
+// Pool - An initialized pool.
+//
+void
+poolinit (PoolTy *Pool, unsigned int NodeSize)
{
assert(Pool && "Null pool pointer passed into poolinit!\n");
@@ -228,12 +239,30 @@
return;
}
+//
+// Function: poolalloc ()
+//
+// Description:
+// Allocates memory from the pool. Typically, we will allocate memory
+// in the same size chunks as we usually do, but sometimes, we will have to
+// allocate more.
+//
void *
-poolalloc(PoolTy *Pool, unsigned NodeSize)
+poolalloc(PoolTy *Pool, unsigned BytesWanted)
{
+ // Pointer to the data block to return
void * Data;
+
assert(Pool && "Null pool pointer passed in to poolalloc!\n");
- assert((NodeSize <= Pool->NodeSize) && "Wrong Node Size!\n");
+
+ //
+ // Determine if we can satisfy this request normally. If not, then
+ // we need to use the array allocation instead.
+ //
+ if (Pool->NodeSize < BytesWanted)
+ {
+ return (poolallocarray (Pool, (BytesWanted / Pool->NodeSize) + 1));
+ }
//
// If we don't have a slab, this is our first initialization. Do some
More information about the llvm-commits
mailing list