Stdlib.hx 1.1 KB

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