CArray.hx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package hl;
  2. #if (hl_ver >= version("1.14.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. @:arrayAccess inline function get( index : Int ) : T return untyped this[index];
  9. public inline function unsafeSet( index : Int, v : T ) : T return untyped this[index] = v;
  10. public static inline function alloc<T>( cl : Class<T>, size : Int ) : CArray<T> {
  11. return cast alloc_carray( (cast cl:BaseType).__type__ , size );
  12. }
  13. @:hlNative("?std","alloc_carray")
  14. static function alloc_carray( t : hl.Type, size : Int ) : CArray<Dynamic> {
  15. return null;
  16. }
  17. public static function fromBytes<T>( bytes : haxe.io.Bytes ) : CArray<T> {
  18. return bytes == null ? null : hl.Api.unsafeCast(@:privateAccess bytes.b);
  19. }
  20. #if (hl_ver >= version("1.16.0"))
  21. public function toBytes( cl : Class<T>, count : Int ) : haxe.io.Bytes {
  22. if( this == null )
  23. return null;
  24. var size = (cast cl:BaseType).__type__.getDataSize();
  25. return @:privateAccess new haxe.io.Bytes(hl.Api.unsafeCast(this),size * count);
  26. }
  27. public inline function blit( cl : Class<T>, pos : Int, src : CArray<T>, srcPos : Int, srcLen : Int ) : Void {
  28. carray_blit( cast this, (cast cl:BaseType).__type__, pos, src, srcPos, srcLen );
  29. }
  30. @:hlNative("?std","carray_blit")
  31. static function carray_blit( dst: CArray<Dynamic>, t : hl.Type, pos : Int, src : CArray<Dynamic>, srcPos : Int, srcLen : Int ) : Void {
  32. }
  33. #end
  34. }
  35. #end