diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2022-02-05 22:18:22 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2022-02-05 22:18:22 +0100 |
| commit | a3d99765cc1012c2bb3e4f7e953c8126a9c158d2 (patch) | |
| tree | aef2224fd7a1383cf82803a6a63adf5d8832aa1d | |
| parent | 25769f139af4384f4f916778bb2695fda8bccef7 (diff) | |
mem: Add `doc.odin` with `Tracking_Allocator` example.
| -rw-r--r-- | core/mem/doc.odin | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/mem/doc.odin b/core/mem/doc.odin new file mode 100644 index 000000000..2a5ee06d3 --- /dev/null +++ b/core/mem/doc.odin @@ -0,0 +1,34 @@ +/* +package mem implements various types of allocators. + + +An example of how to use the `Tracking_Allocator` to track subsequent allocations +in your program and report leaks and bad frees: + +```odin +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) + context.allocator = mem.tracking_allocator(&track) + + _main() + + for _, v in track.allocation_map { + fmt.printf("%v leaked %v bytes", v.location, v.size) + } + for bf in track.bad_free_array { + fmt.printf("%v allocation %p was freed badly", bf.location, bf.memory) + } +} +``` +*/ +package mem
\ No newline at end of file |