diff --git a/std/hl/Gc.hx b/std/hl/Gc.hx index 03df18e2f08..9fa76c0b154 100644 --- a/std/hl/Gc.hx +++ b/std/hl/Gc.hx @@ -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, maxCount:Int = 0) { + var arr = new hl.NativeArray(maxCount); + var count = _getLiveObjects(cast(cl,hl.BaseType).__type__, arr); + var objs = new Array(); + 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. @@ -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):Int { + return 0; + } + #end }