Created
March 3, 2024 20:26
-
-
Save karl-zylinski/4ccf438337123e7c8994df3b03604e33 to your computer and use it in GitHub Desktop.
Example of how to setup tracking allocator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://odin-lang.org/docs/overview/#when-statements, see end of that section | |
package main | |
import "core:fmt" | |
import "core:mem" | |
main :: proc() { | |
when ODIN_DEBUG { | |
track: mem.Tracking_Allocator | |
mem.tracking_allocator_init(&track, context.allocator) | |
context.allocator = mem.tracking_allocator(&track) | |
defer { | |
if len(track.allocation_map) > 0 { | |
fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map)) | |
for _, entry in track.allocation_map { | |
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location) | |
} | |
} | |
if len(track.bad_free_array) > 0 { | |
fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array)) | |
for entry in track.bad_free_array { | |
fmt.eprintf("- %p @ %v\n", entry.memory, entry.location) | |
} | |
} | |
mem.tracking_allocator_destroy(&track) | |
} | |
} | |
// rest of your program goes here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment