diff options
| author | dam <dam@gudinoff> | 2023-02-01 01:28:14 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-02-01 01:28:14 +0000 |
| commit | 46a13cef3a7fa6f12b0a97a64d3a2250914fd445 (patch) | |
| tree | 9e3f49d3a1f6dfeaa23f188d69f4812eae1f5b0f /ttt.jai | |
| parent | 114d85ad9c1d374e52deed138b3d624d3097b0c6 (diff) | |
| download | task-time-tracker-46a13cef3a7fa6f12b0a97a64d3a2250914fd445.tar.zst task-time-tracker-46a13cef3a7fa6f12b0a97a64d3a2250914fd445.zip | |
Added some code that may be usefull to check memory ownership on next compiler versions.
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 59 |
1 files changed, 58 insertions, 1 deletions
@@ -1226,7 +1226,64 @@ main :: () { // TODO DEBUG // Check what's going on with the temp allocator: // Is it really the responsible for these paths? - // It seems that the new compiler allows us to check this pretty easily. + // It seems that the next beta (after 0.1.055b) compiler allows us to check this pretty easily. + /* + // + // An example that uses several different allocators, then asks them all + // who owns which memory. + // + // Note that this is probably not the kind of thing you want to do at runtime + // in the steady state, as it may not be very fast, but it could be a very helpful + // debugging facility. + // + + + #import "Basic"; + #import "Pool"; + #import "Flat_Pool"; + #import "rpmalloc"; + + main :: () { + pool: Pool; + flat: Flat_Pool; + + a := context.default_allocator; + b := Allocator.{pool_allocator_proc, *pool}; + c := Allocator.{flat_pool_allocator_proc, *flat}; + d := Allocator.{rpmalloc_allocator_proc, null}; + + d.proc(.STARTUP, 0, 0, null, null); // rpmalloc needs explicit init right now, but others don't. + + ma := alloc(1000, allocator=a); + mb := alloc(1000, allocator=b); + mc := alloc(1000, allocator=c); + md := alloc(1000, allocator=d); + + report_who_owns(ma, a, b, c, d); + report_who_owns(mb, a, b, c, d); + report_who_owns(mc, a, b, c, d); + report_who_owns(md, a, b, c, d); + } + + report_who_owns :: (memory: *void, allocators: .. Allocator) { + someone_owns_this := false; + + print("Querying all allocators for address: %\n", memory); + + for allocators { + caps, name := get_capabilities(it); + assert((caps & .IS_THIS_YOURS) != 0); // It had better be claiming to support this! + + yours := cast(bool) it.proc(.IS_THIS_YOURS, 0, 0, memory, it.data); + print("[%] says \"%\"\n", yours, name); + + someone_owns_this ||= yours; + } + + assert(someone_owns_this); + } + */ + // free(app_directory); print("bazinga: '%'\n", app_directory); // if make_directory_if_it_does_not_exist(app_directory, false) == false { |
