| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago | 1 | import 'dart:ffi'; |
| 2 | import 'dart:io'; |
| 3 | import 'package:ffi/ffi.dart'; |
| 4 | int rss() => int.parse(File('/proc/self/status').readAsLinesSync() |
| 5 | .firstWhere((l)=>l.startsWith('VmRSS')).split(RegExp(r'\s+'))[1]); |
| 6 | |
| 7 | void main(){ |
| Replace V with Nim 472eb49 nandithebull 8h ago | 8 | final lib = DynamicLibrary.open('libnimflutter.so'); |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago | 9 | final greet = lib.lookupFunction<Pointer<Utf8> Function(Pointer<Utf8>), |
| Replace V with Nim 472eb49 nandithebull 8h ago | 10 | Pointer<Utf8> Function(Pointer<Utf8>)>('nf_greet'); |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago | 11 | final vfree = lib.lookupFunction<Void Function(Pointer<Void>), |
| Replace V with Nim 472eb49 nandithebull 8h ago | 12 | void Function(Pointer<Void>)>('nf_free'); |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago | 13 | |
| Replace V with Nim 472eb49 nandithebull 8h ago | 14 | // Regression guard for the shared-heap ownership rule: RSS must stay flat. |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago | 15 | final arg = 'fixed'.toNativeUtf8(); |
| 16 | for (var i=0;i<5000;i++){ vfree(greet(arg).cast()); } |
| 17 | final before = rss(); |
| 18 | for (var i=0;i<900000;i++){ vfree(greet(arg).cast()); } |
| 19 | print('native-only before: $before kB after: ${rss()} kB'); |
| 20 | calloc.free(arg); |
| 21 | } |