[mem]: Document the package

This commit is contained in:
flysand7
2024-09-07 14:19:50 +11:00
parent c0112d1c70
commit 64814f4199
2 changed files with 119 additions and 23 deletions
+31
View File
@@ -18,6 +18,37 @@ Tracking_Allocator_Bad_Free_Entry :: struct {
location: runtime.Source_Code_Location,
}
/*
An example of how to use the `Tracking_Allocator` to track subsequent allocations
in your program and report leaks and bad frees:
Example:
package foo
import "core:mem"
import "core:fmt"
_main :: proc() {
// do stuff
}
main :: proc() {
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
defer mem.tracking_allocator_destroy(&track)
context.allocator = mem.tracking_allocator(&track)
_main()
for _, leak in track.allocation_map {
fmt.printf("%v leaked %m\n", leak.location, leak.size)
}
for bad_free in track.bad_free_array {
fmt.printf("%v allocation %p was freed badly\n", bad_free.location, bad_free.memory)
}
}
*/
Tracking_Allocator :: struct {
backing: Allocator,
allocation_map: map[rawptr]Tracking_Allocator_Entry,