]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: The C++11 method shrink_to_fit() can be used to release memory
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 5 May 2016 12:22:57 +0000 (14:22 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 5 May 2016 12:22:57 +0000 (14:22 +0200)
vm/sampling_profiler.cpp
vm/vm.hpp

index 3b1e76c4de9a6d482f2269b15749be0b87ec4d09..dc6def6ed2352047b39174ca9eb10b3a234558ef 100644 (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);
index 357955b45ab533692636dbfdc31b470c6ab66bb5..9209ae9e08a8fbc7d5ba03d22786e90b475cce3f 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -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);