Skip to content

Commit

Permalink
[hl] add std.hl.Gc.getLiveObjects for next hl version (#11599)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao authored Mar 28, 2024
1 parent 0671176 commit 433fbdf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions std/hl/Gc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ class Gc {
return v;
}

#if (hl_ver >= version("1.15.0"))
/**
Count live objects of class `cl`, and get at most `maxCount` elements in an array.
**/
public static function getLiveObjects(cl:Class<Dynamic>, maxCount:Int = 0) {
var arr = new hl.NativeArray<Dynamic>(maxCount);
var count = _getLiveObjects(cast(cl,hl.BaseType).__type__, arr);
var objs = new Array<Dynamic>();
for (i in 0...maxCount) {
if (arr[i] == null) break;
objs.push(arr[i]);
}
return {count: count, objs: objs};
}
#end

/**
Enter/leave a blocking section: when in a blocking section the thread cannot
allocate any memory but other threads will not wait for it for collecting memory.
Expand All @@ -89,4 +105,10 @@ class Gc {
}

@:hlNative("std", "gc_set_flags") static function _set_flags(v:Int) {}

#if (hl_ver >= version("1.15.0"))
@:hlNative("std", "gc_get_live_objects") static function _getLiveObjects(type:hl.Type, arr:hl.NativeArray<Dynamic>):Int {
return 0;
}
#end
}

0 comments on commit 433fbdf

Please sign in to comment.