VM: The C++11 method shrink_to_fit() can be used to release memory

locals-and-roots
Björn Lindqvist 2016-05-05 14:22:57 +02:00
parent 5826394573
commit 9824be8714
2 changed files with 3 additions and 11 deletions

View File

@ -67,19 +67,12 @@ void factor_vm::set_sampling_profiler(fixnum rate) {
end_sampling_profiler();
}
void factor_vm::clear_samples() {
// Swapping into temporaries releases the vector's allocated storage,
// whereas clear() would leave the allocation as-is
std::vector<profiling_sample> sample_graveyard;
std::vector<cell> sample_callstack_graveyard;
samples.swap(sample_graveyard);
sample_callstacks.swap(sample_callstack_graveyard);
}
void factor_vm::start_sampling_profiler(fixnum rate) {
samples_per_second = rate;
safepoint.sample_counts.clear();
clear_samples();
// Release the memory consumed by colleting samples.
samples.shrink_to_fit();
sample_callstacks.shrink_to_fit();
samples.reserve(10 * rate);
sample_callstacks.reserve(100 * rate);
atomic::store(&sampling_profiler_p, true);

View File

@ -190,7 +190,6 @@ struct factor_vm {
void primitive_become();
// sampling_profiler
void clear_samples();
void record_sample(bool prolog_p);
void record_callstack_sample(cell* begin, cell* end, bool prolog_p);
void start_sampling_profiler(fixnum rate);