| 77 | } |
| 78 | |
| 79 | void on_free(void* ptr) { |
| 80 | if (!ptr) return; |
| 81 | |
| 82 | auto it = allocations.find(ptr); |
| 83 | if (it != allocations.end()) { |
| 84 | size_t size = it->second; |
| 85 | current_bytes.fetch_sub(size); |
| 86 | free_count.fetch_add(1); |
| 87 | // unsorted_map_fixed has erase(), so we could remove the entry, but for simplicity |
| 88 | // we just mark it as removed by setting size to 0. current_bytes tracking is separate. |
| 89 | allocations[ptr] = 0; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | size_t count_active_allocations() const { |
| 94 | size_t count = 0; |