mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-07 13:33:13 +00:00
mem: Add doc.odin with Tracking_Allocator example.
This commit is contained in:
34
core/mem/doc.odin
Normal file
34
core/mem/doc.odin
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user