mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
Naming and type changes
This commit is contained in:
@@ -22,12 +22,13 @@ Tracking_Allocator :: struct {
|
||||
bad_free_array: [dynamic]Tracking_Allocator_Bad_Free_Entry,
|
||||
mutex: sync.Mutex,
|
||||
clear_on_free_all: bool,
|
||||
allocated: int,
|
||||
alloc_count: int,
|
||||
freed: int,
|
||||
free_count: int,
|
||||
peak: int,
|
||||
current: int,
|
||||
|
||||
total_memory_allocated: i64,
|
||||
total_allocation_count: i64,
|
||||
total_memory_freed: i64,
|
||||
total_free_count: i64,
|
||||
peak_memory_allocated: i64,
|
||||
current_memory_allocated: i64,
|
||||
}
|
||||
|
||||
tracking_allocator_init :: proc(t: ^Tracking_Allocator, backing_allocator: Allocator, internals_allocator := context.allocator) {
|
||||
@@ -50,7 +51,7 @@ tracking_allocator_clear :: proc(t: ^Tracking_Allocator) {
|
||||
sync.mutex_lock(&t.mutex)
|
||||
clear(&t.allocation_map)
|
||||
clear(&t.bad_free_array)
|
||||
t.current = 0
|
||||
t.current_memory_allocated = 0
|
||||
sync.mutex_unlock(&t.mutex)
|
||||
}
|
||||
|
||||
@@ -63,22 +64,24 @@ tracking_allocator :: proc(data: ^Tracking_Allocator) -> Allocator {
|
||||
}
|
||||
}
|
||||
|
||||
track_alloc :: proc(data: ^Tracking_Allocator, entry: ^Tracking_Allocator_Entry) {
|
||||
data.allocated += entry.size
|
||||
data.alloc_count += 1
|
||||
data.current += entry.size
|
||||
if data.current > data.peak do data.peak = data.current
|
||||
}
|
||||
|
||||
track_free :: proc(data: ^Tracking_Allocator, entry: ^Tracking_Allocator_Entry) {
|
||||
data.freed += entry.size
|
||||
data.free_count += 1
|
||||
data.current -= entry.size
|
||||
}
|
||||
|
||||
tracking_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, loc := #caller_location) -> (result: []byte, err: Allocator_Error) {
|
||||
track_alloc :: proc(data: ^Tracking_Allocator, entry: ^Tracking_Allocator_Entry) {
|
||||
data.total_memory_allocated += entry.size
|
||||
data.total_allocation_count += 1
|
||||
data.current_memory_allocated += entry.size
|
||||
if data.current_memory_allocated > data.peak_memory_allocated {
|
||||
data.peak_memory_allocated = data.current_memory_allocated
|
||||
}
|
||||
}
|
||||
|
||||
track_free :: proc(data: ^Tracking_Allocator, entry: ^Tracking_Allocator_Entry) {
|
||||
data.total_memory_freed += entry.size
|
||||
data.total_free_count += 1
|
||||
data.current_memory_allocated -= entry.size
|
||||
}
|
||||
|
||||
data := (^Tracking_Allocator)(allocator_data)
|
||||
|
||||
sync.mutex_guard(&data.mutex)
|
||||
@@ -129,7 +132,7 @@ tracking_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
case .Free_All:
|
||||
if data.clear_on_free_all {
|
||||
clear_map(&data.allocation_map)
|
||||
data.current = 0
|
||||
data.current_memory_allocated = 0
|
||||
}
|
||||
case .Resize, .Resize_Non_Zeroed:
|
||||
if old_memory != nil && old_memory in data.allocation_map {
|
||||
|
||||
Reference in New Issue
Block a user