mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Update delete to pass size in bytes to free when possible
This commit is contained in:
@@ -36,12 +36,21 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
|
|||||||
location = location,
|
location = location,
|
||||||
)
|
)
|
||||||
case .Free:
|
case .Free:
|
||||||
logf(
|
if old_size != 0 {
|
||||||
level=la.level,
|
logf(
|
||||||
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)",
|
level=la.level,
|
||||||
args = {la.prefix, " " if la.prefix != "" else "", old_memory, old_size},
|
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)",
|
||||||
location = location,
|
args = {la.prefix, " " if la.prefix != "" else "", old_memory, old_size},
|
||||||
)
|
location = location,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
logf(
|
||||||
|
level=la.level,
|
||||||
|
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p)",
|
||||||
|
args = {la.prefix, " " if la.prefix != "" else "", old_memory},
|
||||||
|
location = location,
|
||||||
|
)
|
||||||
|
}
|
||||||
case .Free_All:
|
case .Free_All:
|
||||||
logf(
|
logf(
|
||||||
level=la.level,
|
level=la.level,
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ free_all :: proc{mem_free_all}
|
|||||||
|
|
||||||
@builtin
|
@builtin
|
||||||
delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
||||||
return mem_free(raw_data(str), allocator, loc)
|
return mem_free_with_size(raw_data(str), len(str), allocator, loc)
|
||||||
}
|
}
|
||||||
@builtin
|
@builtin
|
||||||
delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
||||||
@@ -151,17 +151,24 @@ delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #cal
|
|||||||
}
|
}
|
||||||
@builtin
|
@builtin
|
||||||
delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) -> Allocator_Error {
|
delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) -> Allocator_Error {
|
||||||
return mem_free(raw_data(array), array.allocator, loc)
|
return mem_free_with_size(raw_data(array), cap(array)*size_of(E), array.allocator, loc)
|
||||||
}
|
}
|
||||||
@builtin
|
@builtin
|
||||||
delete_slice :: proc(array: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
delete_slice :: proc(array: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
||||||
return mem_free(raw_data(array), allocator, loc)
|
return mem_free_with_size(raw_data(array), len(array)*size_of(E), allocator, loc)
|
||||||
}
|
}
|
||||||
@builtin
|
@builtin
|
||||||
delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) -> Allocator_Error {
|
delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) -> Allocator_Error {
|
||||||
|
Entry :: struct {
|
||||||
|
hash: uintptr,
|
||||||
|
next: int,
|
||||||
|
key: K,
|
||||||
|
value: V,
|
||||||
|
}
|
||||||
|
|
||||||
raw := transmute(Raw_Map)m
|
raw := transmute(Raw_Map)m
|
||||||
err := delete_slice(raw.hashes, raw.entries.allocator, loc)
|
err := delete_slice(raw.hashes, raw.entries.allocator, loc)
|
||||||
err1 := mem_free(raw.entries.data, raw.entries.allocator, loc)
|
err1 := mem_free_with_size(raw.entries.data, raw.entries.cap*size_of(Entry), raw.entries.allocator, loc)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = err1
|
err = err1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,14 @@ mem_free :: #force_inline proc(ptr: rawptr, allocator := context.allocator, loc
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mem_free_with_size :: #force_inline proc(ptr: rawptr, byte_count: int, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
||||||
|
if ptr == nil || allocator.procedure == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err := allocator.procedure(allocator.data, .Free, 0, 0, ptr, byte_count, loc)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
mem_free_bytes :: #force_inline proc(bytes: []byte, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
mem_free_bytes :: #force_inline proc(bytes: []byte, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
|
||||||
if bytes == nil || allocator.procedure == nil {
|
if bytes == nil || allocator.procedure == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user