2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

59 строки
1.5 KiB

  1. #include "IZ_pool.h"
  2. void IZ_PoolInitialize(IZ_Pool* pool, size_t size) {
  3. IZ_LogInfo(IZ_LOG_CATEGORY_GLOBAL, "memory", "Setting up pool...");
  4. IZ_ListInitialize(&pool->items);
  5. pool->memory = IZ_malloc(size);
  6. IZ_memset(pool->memory, 0, size);
  7. pool->allocated_memory = 0;
  8. pool->next_address = 0;
  9. pool->max_size = size;
  10. }
  11. IZ_PoolItem* IZ_PoolAllocate(IZ_Pool* pool, IZ_PoolAllocationArgs args) {
  12. // 1. check next free allocation for size
  13. // 2. if 1. returns non-null,
  14. // u64 alloc_end = pool->next_address + size;
  15. //
  16. // for (u64 i = 0; i < POOL_MAX_ALLOCATIONS; i += 1) {
  17. // if (pool->allocation[i].length == 0) {
  18. // continue;
  19. // }
  20. // }
  21. if (pool->max_size - pool->allocated_memory < args.size) {
  22. // TODO deallocate memory based from priority
  23. }
  24. void* pointer = &((u8*) pool->memory)[pool->next_address];
  25. IZ_ListNode* new_item;
  26. IZ_ListAppendNode(&pool->items, &(IZ_PoolItem) {
  27. .pointer = pointer,
  28. .args = args,
  29. .pool = pool,
  30. }, &new_item);
  31. pool->next_address = (pool->next_address + args.size) % POOL_MAX_SIZE;
  32. pool->allocated_memory += args.size;
  33. return new_item->value;
  34. }
  35. bool IZ_PoolGetSameItem(IZ_ListNode** node, u64 _index, IZ_List* list) {
  36. return (*node)->value == (*list->iterator)->value;
  37. }
  38. void IZ_PoolDeallocate(IZ_PoolItem* item) {
  39. IZ_ListNode* node;
  40. IZ_ListFindFirstNode(&item->pool->items, IZ_PoolGetSameItem, &node);
  41. if (node) {
  42. IZ_ListDeleteNode(node);
  43. }
  44. }
  45. void IZ_PoolTeardown(IZ_Pool* pool) {
  46. IZ_LogInfo(IZ_LOG_CATEGORY_GLOBAL, "memory", "Shutting down pool...");
  47. IZ_free(pool->memory);
  48. pool->memory = NULL;
  49. }