allocators.cpp 822 B

1234567891011121314151617181920212223242526272829303132
  1. #include "Allocator.h"
  2. #include "HeapAllocator.h"
  3. #include "StackAllocator.h"
  4. #include <cstdio>
  5. #include "Assert.h"
  6. using namespace crown;
  7. int main()
  8. {
  9. HeapAllocator malloc_allocator;
  10. char* char_buffer = (char*)malloc_allocator.allocate(128);
  11. CE_ASSERT(malloc_allocator.allocated_size() >= 128, "Allocated size differs from requested size");
  12. printf("HeapAllocator::get_allocated_size(): %d\n", (uint32_t)malloc_allocator.allocated_size());
  13. malloc_allocator.deallocate(char_buffer);
  14. printf("HeapAllocator::get_allocated_size(): %d\n", (uint32_t)malloc_allocator.allocated_size());
  15. //CE_ASSERT(malloc_allocator.get_allocated_size() == 0);
  16. uint8_t buffer[1024 * 1024];
  17. StackAllocator stack(buffer, 1024 * 1024);
  18. stack.allocate(12);
  19. stack.allocate(5);
  20. memory::dump(buffer, stack.allocated_size(), 4);
  21. }