Browse Source

[hl] add std.hl.Gc.getLiveObjects for next hl version (#11599)

Yuxiao Mao 1 year ago
parent
commit
433fbdf33b
1 changed files with 22 additions and 0 deletions
  1. 22 0
      std/hl/Gc.hx

+ 22 - 0
std/hl/Gc.hx

@@ -69,6 +69,22 @@ class Gc {
 		return v;
 		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
 		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.
 		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) {}
 	@: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
 }
 }