CArray.hx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package hl;
  2. #if (hl_ver >= version("1.13.0"))
  3. /**
  4. CArray is a compact array where all objects are memory aligned and stored as a single GC block.
  5. You must hold a reference to the CArray while any of the objects it contains is still referenced somewhere.
  6. **/
  7. abstract CArray<T>(Abstract<"hl_carray">) {
  8. public var length(get,never) : Int;
  9. #if (hl_ver >= version("1.14.0"))
  10. inline function get_length() return untyped $asize(this);
  11. @:arrayAccess inline function get( index : Int ) : T return untyped this[index];
  12. #else
  13. inline function get_length() return getLen(cast this);
  14. @:arrayAccess inline function get( index : Int ) : T return getIndex(cast this, index);
  15. #end
  16. public static function alloc<T>( cl : Class<T>, size : Int ) : CArray<T> {
  17. return cast alloc_carray( (cast cl:BaseType).__type__ , size );
  18. }
  19. @:hlNative("?std","carray_get")
  20. static function getIndex( arr : CArray<Dynamic>, index : Int ) : Dynamic {
  21. return null;
  22. }
  23. @:hlNative("?std","carray_length")
  24. static function getLen( arr : CArray<Dynamic> ) : Int {
  25. return 0;
  26. }
  27. @:hlNative("?std","alloc_carray")
  28. static function alloc_carray( t : hl.Type, size : Int ) : CArray<Dynamic> {
  29. return null;
  30. }
  31. }
  32. #end