From e8c5b5abb5e047a24433c617975dfb6123eb346e Mon Sep 17 00:00:00 2001 From: Hugh Date: Sun, 2 Mar 2014 10:48:04 +0800 Subject: [PATCH] [cpp] Add hxcpp_api_level to allow backwards compatibility in both haxe and c++ code. Add additional memory usage statistics --- common.ml | 2 ++ gencpp.ml | 3 ++- main.ml | 1 + std/cpp/vm/Gc.hx | 19 ++++++++++++++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common.ml b/common.ml index 138f0b4079a..e41dc33b964 100644 --- a/common.ml +++ b/common.ml @@ -183,6 +183,7 @@ module Define = struct | GencommonDebug | HaxeBoot | HaxeVer + | HxcppApiLevel | IncludePrefix | Interp | JavaVer @@ -252,6 +253,7 @@ module Define = struct | GencommonDebug -> ("gencommon_debug","GenCommon internal") | HaxeBoot -> ("haxe_boot","Given the name 'haxe' to the flash boot class instead of a generated name") | HaxeVer -> ("haxe_ver","The current Haxe version value") + | HxcppApiLevel -> ("hxcpp_api_level","Provided to allow compatibility between hxcpp versions") | IncludePrefix -> ("include_prefix","prepend path to generated include files") | Interp -> ("interp","The code is compiled to be run with --interp") | JavaVer -> ("java_ver", " Sets the Java version to be targeted") diff --git a/gencpp.ml b/gencpp.ml index 608a15048ba..40984d73055 100644 --- a/gencpp.ml +++ b/gencpp.ml @@ -3591,7 +3591,8 @@ let write_build_data common_ctx filename classes main_deps build_extra exe_name in output_string buildfile "\n"; - output_string buildfile "\n"; + output_string buildfile ("\n"); output_string buildfile "\n"; output_string buildfile "\n"; List.iter add_class_to_buildfile classes; diff --git a/main.ml b/main.ml index 695487df04c..f02bef37af9 100755 --- a/main.ml +++ b/main.ml @@ -929,6 +929,7 @@ try let interp = ref false in let swf_version = ref false in Common.define_value com Define.HaxeVer (float_repres (float_of_int version /. 10000.)); + Common.define_value com Define.HxcppApiLevel "310"; Common.raw_define com "haxe3"; Common.define_value com Define.Dce "std"; com.warning <- (fun msg p -> message ctx ("Warning : " ^ msg) p); diff --git a/std/cpp/vm/Gc.hx b/std/cpp/vm/Gc.hx index e603c28b40d..799f096a194 100644 --- a/std/cpp/vm/Gc.hx +++ b/std/cpp/vm/Gc.hx @@ -23,6 +23,11 @@ package cpp.vm; class Gc { + public static inline var MEM_INFO_USAGE = 0; + public static inline var MEM_INFO_RESERVED = 1; + public static inline var MEM_INFO_CURRENT = 2; + public static inline var MEM_INFO_LARGE = 3; + static public function enable(inEnable:Bool) : Void { untyped __global__.__hxcpp_enable(inEnable); @@ -38,9 +43,21 @@ class Gc untyped __global__.__hxcpp_gc_compact(); } + // Introduced hxcpp_api_level 310 + // Returns stats on memory usage: + // MEM_INFO_USAGE - estimate of how much is needed by program (at last collect) + // MEM_INFO_RESERVED - memory allocated for possible use + // MEM_INFO_CURRENT - memory in use, includes uncollected garbage. + // This will generally saw-tooth between USAGE and RESERVED + // MEM_INFO_LARGE - Size of separate pool used for large allocs. Included in all the above. + static public function memInfo(inWhatInfo:Int) : Int + { + return untyped __global__.__hxcpp_gc_mem_info(inWhatInfo); + } + static public function memUsage() : Int { - return untyped __global__.__hxcpp_gc_used_bytes(); + return untyped __global__.__hxcpp_gc_mem_info(MEM_INFO_USAGE); } static public function trace(sought:Class,printInstances:Bool=true) : Int