Skip to content

Commit

Permalink
[cpp] Add hxcpp_api_level to allow backwards compatibility in both ha…
Browse files Browse the repository at this point in the history
…xe and c++ code. Add additional memory usage statistics
  • Loading branch information
hughsando committed Mar 2, 2014
1 parent df4964d commit e8c5b5a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ module Define = struct
| GencommonDebug
| HaxeBoot
| HaxeVer
| HxcppApiLevel
| IncludePrefix
| Interp
| JavaVer
Expand Down Expand Up @@ -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", "<version:5-7> Sets the Java version to be targeted")
Expand Down
3 changes: 2 additions & 1 deletion gencpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3591,7 +3591,8 @@ let write_build_data common_ctx filename classes main_deps build_extra exe_name
in

output_string buildfile "<xml>\n";
output_string buildfile "<set name=\"HXCPP_API_LEVEL\" value=\"1\" />\n";
output_string buildfile ("<set name=\"HXCPP_API_LEVEL\" value=\"" ^
(Common.defined_value common_ctx Define.HxcppApiLevel) ^ "\" />\n");
output_string buildfile "<files id=\"haxe\">\n";
output_string buildfile "<compilerflag value=\"-Iinclude\"/>\n";
List.iter add_class_to_buildfile classes;
Expand Down
1 change: 1 addition & 0 deletions main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion std/cpp/vm/Gc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Dynamic>,printInstances:Bool=true) : Int
Expand Down

0 comments on commit e8c5b5a

Please sign in to comment.