2020-03-07 11:13:08 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string.h>
|
|
|
|
#include "driver/CustomAssert.h"
|
|
|
|
#include "driver/ConsecutivePoolAllocator.h"
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
|
|
|
#include "driver/vkExt.h"
|
|
|
|
|
|
|
|
void simpleTest()
|
|
|
|
{
|
|
|
|
uint32_t blocksize = 16;
|
|
|
|
uint32_t numblocks = 8;
|
|
|
|
uint32_t size = numblocks * blocksize;
|
|
|
|
|
|
|
|
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem1 = consecutivePoolAllocate(&cpa, 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem2 = consecutivePoolAllocate(&cpa, 2);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem3 = consecutivePoolAllocate(&cpa, 3);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem11 = consecutivePoolAllocate(&cpa, 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem111 = consecutivePoolAllocate(&cpa, 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem0 = consecutivePoolAllocate(&cpa, 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
fprintf(stderr, "\n%p\n", mem0);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem11), 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem111), 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem2), 2);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem3), 3);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem1), 1);
|
2020-03-07 11:13:08 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
}
|
|
|
|
|
2020-03-07 18:07:07 +00:00
|
|
|
void allocTest(uint32_t numToAlloc)
|
|
|
|
{
|
|
|
|
uint32_t blocksize = 16;
|
|
|
|
uint32_t numblocks = 8;
|
|
|
|
uint32_t size = numblocks * blocksize;
|
|
|
|
|
|
|
|
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
|
|
|
|
//CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem1 = consecutivePoolAllocate(&cpa, numToAlloc);
|
2020-03-07 18:07:07 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
fprintf(stderr, "\nmem %p\n", mem1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void freeOneTest(uint32_t which)
|
|
|
|
{
|
|
|
|
uint32_t blocksize = 16;
|
|
|
|
uint32_t numblocks = 8;
|
|
|
|
uint32_t size = numblocks * blocksize;
|
|
|
|
|
|
|
|
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
|
|
|
|
//CPAdebugPrint(&cpa);
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
uint32_t mem[8];
|
2020-03-07 18:07:07 +00:00
|
|
|
for(uint32_t c = 0; c < 8; ++c)
|
|
|
|
{
|
|
|
|
mem[c] = consecutivePoolAllocate(&cpa, 1);
|
|
|
|
}
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem[which]), 1);
|
2020-03-07 18:07:07 +00:00
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
//fprintf(stderr, "\nmem %p\n", mem);
|
|
|
|
}
|
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
void reallocTest()
|
|
|
|
{
|
|
|
|
uint32_t blocksize = 16;
|
|
|
|
uint32_t numblocks = 3;
|
|
|
|
uint32_t size = numblocks * blocksize;
|
|
|
|
|
|
|
|
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
uint32_t mem1 = consecutivePoolAllocate(&cpa, 1);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
uint32_t mem2 = consecutivePoolAllocate(&cpa, 1);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem1), 1);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
mem2 = consecutivePoolReAllocate(&cpa, getCPAptrFromOffset(&cpa, mem2), 1);
|
|
|
|
CPAdebugPrint(&cpa);
|
|
|
|
|
|
|
|
uint32_t mem0 = consecutivePoolAllocate(&cpa, 1);
|
|
|
|
fprintf(stderr, "\n%p\n", mem0);
|
|
|
|
}
|
|
|
|
|
2020-03-07 11:13:08 +00:00
|
|
|
int main() {
|
2020-05-16 13:17:03 +01:00
|
|
|
// simpleTest();
|
|
|
|
|
|
|
|
reallocTest();
|
2020-03-07 18:07:07 +00:00
|
|
|
|
2020-05-16 13:17:03 +01:00
|
|
|
// allocTest(1);
|
|
|
|
// allocTest(3);
|
|
|
|
// allocTest(8);
|
|
|
|
// allocTest(9);
|
2020-03-07 11:13:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|