MCPcopy Create free account
hub / github.com/defold/defold / Free

Function Free

engine/resource/src/block_allocator.cpp:101–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99 }
100
101 void Free(HContext context, void* data, uint32_t size)
102 {
103 uint16_t* ptr = (uint16_t*)data;
104 --ptr;
105 uint16_t block_index = *ptr;
106 if (block_index == MAX_BLOCK_COUNT)
107 {
108 free(ptr);
109 return;
110 }
111 assert(block_index < MAX_BLOCK_COUNT);
112 uint16_t allocation_size = DM_ALIGN(sizeof(uint16_t) + size, BLOCK_ALLOCATION_ALIGNEMENT);
113 Block* block = context->m_Blocks[block_index];
114 assert(block != 0x0);
115 BlockData* block_data = &context->m_BlockDatas[block_index];
116 assert(block_data->m_AllocationCount > 0);
117
118 block_data->m_AllocationCount--;
119 if (0 == block_data->m_AllocationCount)
120 {
121 if (block_index != 0)
122 {
123 delete block;
124 context->m_Blocks[block_index] = 0x0;
125 }
126 return;
127 }
128 if ((uint8_t*)ptr == &block->m_Data[block_data->m_LowWaterMark])
129 {
130 block_data->m_LowWaterMark += allocation_size;
131 }
132 else if ((uint8_t*)ptr == &block->m_Data[block_data->m_HighWaterMark - allocation_size])
133 {
134 block_data->m_HighWaterMark -= allocation_size;
135 }
136 }
137
138 HContext CreateContext()
139 {

Callers 2

CreateResourceFunction · 0.70
TESTFunction · 0.50

Calls 2

freeFunction · 0.85
assertFunction · 0.50

Tested by 1

TESTFunction · 0.40