[llvm-commits] CVS: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
John Criswell
criswell at cs.uiuc.edu
Mon Nov 10 17:13:02 PST 2003
Changes in directory poolalloc/runtime/FreeListAllocator:
PoolAllocator.cpp updated: 1.3 -> 1.4
---
Log message:
Moved the free list allocator to use the PageManager. Now slabs are
allocated on page boundaries.
---
Diffs of the changes: (+19 -3)
Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.3 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.4
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.3 Mon Nov 10 16:31:11 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp Mon Nov 10 17:12:02 2003
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "PoolAllocator.h"
+#include "PageManager.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -56,7 +57,7 @@
// Allocate memory for a new slab and initialize the slab.
//
struct SlabHeader *
-createSlab (unsigned int NodeSize, unsigned int NodesPerSlab = 128)
+createSlab (unsigned int NodeSize, unsigned int NodesPerSlab = 0)
{
// Pointer to the new Slab
struct SlabHeader * NewSlab;
@@ -65,15 +66,25 @@
NodePointer p;
//
+ // Determine how many nodes should exist within a slab.
+ //
+ if (NodesPerSlab == 0)
+ {
+ NodesPerSlab = (PageSize - sizeof (struct SlabHeader)) / (sizeof (unsigned char *) + NodeSize);
+ }
+
+ //
// Determine the size of the slab.
//
int slab_size = ((sizeof (unsigned char *) + NodeSize) * NodesPerSlab) +
sizeof (struct SlabHeader);
+ assert (slab_size <= PageSize);
+
//
// Allocate a piece of memory for the new slab.
//
- NewSlab = (struct SlabHeader *) malloc (slab_size);
+ NewSlab = (struct SlabHeader *) AllocatePage ();
assert (NewSlab != NULL);
//
@@ -154,6 +165,11 @@
Pool->FreeList = NULL;
Pool->FreeablePool = 1;
+ //
+ // Initialize the page manager.
+ //
+ InitializePageManager ();
+
return;
}
@@ -173,7 +189,7 @@
assert(Pool && "Null pool pointer passed in to pooldestroy!\n");
for (Slabp = Pool->Slabs; Slabp != NULL; Slabp=Slabp->Next)
{
- free (Slabp);
+ FreePage (Slabp);
}
return;
More information about the llvm-commits
mailing list