Skip to content

Commit

Permalink
Rename TrackedAllocator to ProfiledAllocator (since "tracked allocato…
Browse files Browse the repository at this point in the history
…r" is already a concept in core library)
  • Loading branch information
oskarnp committed Nov 6, 2022
1 parent e6609f4 commit 962515b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions allocator.odin
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ package tracy
import "core:c"
import "core:mem"

TrackedAllocatorData :: struct {
ProfiledAllocatorData :: struct {
backing_allocator: mem.Allocator,
tracked_allocator: mem.Allocator,
profiled_allocator: mem.Allocator,
callstack_size: i32,
secure: b32,
}

TrackedAllocator :: proc(
self: ^TrackedAllocatorData,
MakeProfiledAllocator :: proc(
self: ^ProfiledAllocatorData,
callstack_size: i32 = TRACY_CALLSTACK,
secure: b32 = false,
backing_allocator := context.allocator) -> mem.Allocator {

self.callstack_size = callstack_size
self.secure = secure
self.backing_allocator = backing_allocator
self.tracked_allocator = mem.Allocator{
self.profiled_allocator = mem.Allocator{
data = self,
procedure = proc(allocator_data: rawptr, mode: mem.Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, location := #caller_location) -> ([]byte, mem.Allocator_Error) {
using self := cast(^TrackedAllocatorData) allocator_data
using self := cast(^ProfiledAllocatorData) allocator_data
new_memory, error := self.backing_allocator.procedure(self.backing_allocator.data, mode, size, alignment, old_memory, old_size, location)
if error == .None {
switch mode {
Expand All @@ -44,7 +44,7 @@ TrackedAllocator :: proc(
return new_memory, error
},
}
return self.tracked_allocator
return self.profiled_allocator
}

@(private="file")
Expand Down
4 changes: 2 additions & 2 deletions demo/demo.odin
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ main :: proc() {
}

// Profile heap allocations with Tracy for this context.
context.allocator = tracy.TrackedAllocator(
self = &tracy.TrackedAllocatorData{},
context.allocator = tracy.MakeProfiledAllocator(
self = &tracy.ProfiledAllocatorData{},
callstack_size = 5,
backing_allocator = context.allocator,
secure = true
Expand Down

0 comments on commit 962515b

Please sign in to comment.