| 157 | } |
| 158 | |
| 159 | void BNativeHeap::free(void* address) { |
| 160 | if (!address) { |
| 161 | return; |
| 162 | } |
| 163 | U32 index = *(((U32*)address) - 1); |
| 164 | if (index >= BNATIVEHEAD_64K_BLOCK_SIZE) { |
| 165 | U8* rawAddress = ((U8*)address) - 4; |
| 166 | if (delayedFree) { |
| 167 | delayedFreeLargeBlocks.set(rawAddress, KSystem::getMilliesSinceStart()); |
| 168 | } else { |
| 169 | Platform::releaseNativeMemory(rawAddress, index); |
| 170 | } |
| 171 | largeBlocks.remove(rawAddress); |
| 172 | return; |
| 173 | } |
| 174 | if (delayedFree) { |
| 175 | U32* pTime = (U32*)address; |
| 176 | pTime--; |
| 177 | if (isCodeMemory) { |
| 178 | Platform::writeCodeToMemory(pTime, 4, [pTime]() { |
| 179 | *pTime = KSystem::getMilliesSinceStart(); |
| 180 | }); |
| 181 | } else { |
| 182 | *pTime = KSystem::getMilliesSinceStart(); |
| 183 | } |
| 184 | } |
| 185 | buckets[index].push_front(address); |
| 186 | } |
nothing calls this directly
no test coverage detected