-
-
Save saenai255/e1c2f67901feffa3676c236a9fefe4e3 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