| 113 | return __alloc(slots[idx].slotsize); |
| 114 | } |
| 115 | int dealloc(void* ptr, size_t size) { |
| 116 | auto idx = get_slot(size); |
| 117 | if (unlikely(idx >= N_SLOTS || |
| 118 | (in_pool_size + slots[idx].slotsize >= trim_threshold))) { |
| 119 | // big block or in-pool buffers reaches to threshold |
| 120 | __dealloc(ptr, idx >= N_SLOTS ? size : slots[idx].slotsize); |
| 121 | return 0; |
| 122 | } |
| 123 | // Collect into pool |
| 124 | in_pool_size += slots[idx].slotsize; |
| 125 | slots[idx].put(ptr); |
| 126 | return 0; |
| 127 | } |
| 128 | size_t trim(size_t keep_size) { |
| 129 | size_t count = 0; |
| 130 | for (int i = 0; in_pool_size > keep_size; i = (i + 1) % N_SLOTS) { |
no test coverage detected