Stdlib.hx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cpp;
  2. @:include("stdlib.h")
  3. extern class Stdlib
  4. {
  5. @:native("malloc")
  6. public static function nativeMalloc(bytes:Int) : cpp.RawPointer<cpp.Void> return null;
  7. @:native("calloc")
  8. public static function nativeCalloc(bytes:Int) : cpp.RawPointer<cpp.Void> return null;
  9. @:native("realloc")
  10. public static function nativeRealloc(inPtr:cpp.RawPointer<cpp.Void>,bytes:Int) : cpp.RawPointer<cpp.Void> return null;
  11. @:native("free")
  12. public static function nativeFree(ptr:cpp.RawPointer<cpp.Void>) : Void { }
  13. @:native("memcpy")
  14. public static function nativeMemcpy(dest:cpp.RawPointer<cpp.Void>, src:cpp.RawConstPointer<cpp.Void>, bytes:Int) : Void { }
  15. @:native("hx::ClassSizeOf") @:templatedCall
  16. public static function sizeof<T>(t:T) : Int { }
  17. inline public static function memcpy<DEST,SRC>(dest:cpp.Pointer<DEST>, src:cpp.ConstPointer<SRC>, bytes:Int) : Void
  18. nativeMemcpy(cast dest.ptr, cast src.ptr, bytes);
  19. inline public static function malloc<T>(bytes:Int) : cpp.Pointer<T>
  20. return cast nativeMalloc(bytes);
  21. inline public static function calloc<T>(bytes:Int) : cpp.Pointer<T>
  22. return cast nativeCalloc(bytes);
  23. inline public static function realloc<T>(ioPtr:cpp.Pointer<T>, bytes:Int) : Void
  24. ioPtr.setRaw( nativeRealloc(cast ioPtr.ptr, bytes) );
  25. inline public static function free<T>(ptr:cpp.Pointer<T>) : Void
  26. {
  27. if (ptr!=null)
  28. {
  29. nativeFree(cast ptr.ptr);
  30. ptr.ptr = null;
  31. }
  32. }
  33. }