Files
CodenameEngine/source/funkin/utils/MemoryUtil.hx
T
2023-01-17 21:23:32 +01:00

78 lines
1.4 KiB
Haxe

package funkin.utils;
#if cpp
import cpp.vm.Gc;
#elseif hl
import hl.Gc;
#elseif java
import java.vm.Gc;
#elseif neko
import neko.vm.Gc;
#end
import openfl.system.System;
class MemoryUtil {
public static function init() {
#if cpp
#end
}
public static function clearMinor() {
#if (cpp || java || neko)
Gc.run(false);
#end
}
public static function clearMajor() {
#if cpp
Gc.run(true);
Gc.compact();
#elseif hl
Gc.major();
#elseif (java || neko)
Gc.run(true);
#end
}
public static function enable() {
#if (cpp || hl)
Gc.enable(true);
#end
}
public static function disable() {
#if (cpp || hl)
Gc.enable(false);
#end
}
public static inline function currentMemUsage() {
#if cpp
return Gc.memInfo64(Gc.MEM_INFO_USAGE);
#elseif sys
return cast(cast(System.totalMemory, UInt), Float);
#else
return 0;
#end
}
private static var _nb:Int = 0;
private static var _nbD:Int = 0;
private static var _zombie:Dynamic;
public static function destroyFlixelZombies() {
#if cpp
// Gc.enterGCFreeZone();
while ((_zombie = Gc.getNextZombie()) != null) {
_nb++;
if (_zombie is flixel.util.FlxDestroyUtil.IFlxDestroyable) {
flixel.util.FlxDestroyUtil.destroy(cast(_zombie, flixel.util.FlxDestroyUtil.IFlxDestroyable));
_nbD++;
}
}
Sys.println('Zombies: ${_nb}; IFlxDestroyable Zombies: ${_nbD}');
// Gc.exitGCFreeZone();
#end
}
}