Browse Source

Add `mem.tracking_allocator_reset`

Feoramund 1 year ago
parent
commit
8137b9dd75
1 changed files with 14 additions and 0 deletions
  1. 14 0
      core/mem/tracking_allocator.odin

+ 14 - 0
core/mem/tracking_allocator.odin

@@ -47,6 +47,7 @@ tracking_allocator_destroy :: proc(t: ^Tracking_Allocator) {
 }
 
 
+// Clear only the current allocation data while keeping the totals intact.
 tracking_allocator_clear :: proc(t: ^Tracking_Allocator) {
 	sync.mutex_lock(&t.mutex)
 	clear(&t.allocation_map)
@@ -55,6 +56,19 @@ tracking_allocator_clear :: proc(t: ^Tracking_Allocator) {
 	sync.mutex_unlock(&t.mutex)
 }
 
+// Reset all of a Tracking Allocator's allocation data back to zero.
+tracking_allocator_reset :: proc(t: ^Tracking_Allocator) {
+	sync.mutex_lock(&t.mutex)
+	clear(&t.allocation_map)
+	clear(&t.bad_free_array)
+	t.total_memory_allocated = 0
+	t.total_allocation_count = 0
+	t.total_memory_freed = 0
+	t.total_free_count = 0
+	t.peak_memory_allocated = 0
+	t.current_memory_allocated = 0
+	sync.mutex_unlock(&t.mutex)
+}
 
 @(require_results)
 tracking_allocator :: proc(data: ^Tracking_Allocator) -> Allocator {