TEST(AllocatorTest, Basics) {
BumpPtrAllocator Alloc;
- int *a = (int*)Alloc.Allocate(sizeof(int), 0);
- int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 0);
- int *c = (int*)Alloc.Allocate(sizeof(int), 0);
+ int *a = (int*)Alloc.Allocate(sizeof(int), 1);
+ int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 1);
+ int *c = (int*)Alloc.Allocate(sizeof(int), 1);
*a = 1;
b[0] = 2;
b[9] = 2;
// Allocate enough bytes to create three slabs.
TEST(AllocatorTest, ThreeSlabs) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(3U, Alloc.GetNumSlabs());
}
// again.
TEST(AllocatorTest, TestReset) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
Alloc.Reset();
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
}
BumpPtrAllocator Alloc;
// Fill the slab right up until the end pointer.
- Alloc.Allocate(4096, 0);
+ Alloc.Allocate(4096, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
// If we don't allocate a new slab, then we will have overflowed.
- Alloc.Allocate(1, 0);
+ Alloc.Allocate(1, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
}
TEST(AllocatorTest, TestSmallSlabSize) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(8000, 0);
- EXPECT_EQ(2U, Alloc.GetNumSlabs());
+ Alloc.Allocate(8000, 1);
+ EXPECT_EQ(1U, Alloc.GetNumSlabs());
}
// Mock slab allocator that returns slabs aligned on 4096 bytes. There is no
void *MemBase = malloc(Size + Alignment - 1 + sizeof(void*));
// Find the slab start.
- void *Slab = alignPtr((char *)MemBase + sizeof(void *), Alignment);
+ void *Slab = (void *)alignAddr((char*)MemBase + sizeof(void *), Alignment);
// Hold a pointer to the base so we can free the whole malloced block.
((void**)Slab)[-1] = MemBase;
BumpPtrAllocatorImpl<MockSlabAllocator> Alloc;
// First allocate a tiny bit to ensure we have to re-align things.
- (void)Alloc.Allocate(1, 0);
+ (void)Alloc.Allocate(1, 1);
// Now the big chunk with a big alignment.
(void)Alloc.Allocate(3000, 2048);