[alloc-pool] Reduce memory usage by reclaiming some discards

This commit is contained in:
Behdad Esfahbod committed 2025-09-18 11:18:09 -04:00
1 parent a22add2530
commit e1fd2beeec
3 files changed
+21 -2

No files matched your search

+8
View File
@@ -88,6 +88,14 @@ struct hb_alloc_pool_t
return ret;
}
void discard (void *p_, size_t size)
{
// Reclaim memory if we can.
char *p = (char *) p_;
if (current_chunk.arrayZ == p + size && current_chunk.backwards_length >= size)
current_chunk -= size;
}
private:
hb_vector_t<hb_vector_t<char>> chunks;
hb_array_t<char> current_chunk;
+2 -2
View File
@@ -523,7 +523,7 @@ struct tuple_delta_t
o->tupleIndex = flag;
unsigned total_header_len = 4 + (peak_count + interim_count) * (F2DOT14::static_size);
compiled_tuple_header.shrink (total_header_len, false);
compiled_tuple_header.shrink_back_to_pool (pool, total_header_len);
return true;
}
@@ -600,7 +600,7 @@ struct tuple_delta_t
if (j != rounded_deltas.length) return false;
encoded_len += compile_deltas (compiled_deltas.as_array ().sub_array (encoded_len), rounded_deltas);
}
compiled_deltas.shrink (encoded_len, false);
compiled_deltas.shrink_back_to_pool (pool, encoded_len);
return true;
}
+11
View File
@@ -574,6 +574,17 @@ struct hb_vector_t
return true;
}
template <typename allocator_t>
void shrink_back_to_pool (allocator_t *allocator, int size)
{
unsigned orig_length = length;
shrink (size, false);
if (allocator && !is_owned ())
allocator->discard (arrayZ + length, (orig_length - length) * sizeof (Type));
}
HB_ALWAYS_INLINE_VECTOR_ALLOCS
bool resize_full (int size_, bool initialize, bool exact)
{