Преглед изворни кода

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

Yuxiao Mao пре 1 година
родитељ
комит
433fbdf33b
1 измењених фајлова са 22 додато и 0 уклоњено
  1. 22 0
      std/hl/Gc.hx

+ 22 - 0
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<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.
@@ -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
 }