nandi/vflutter_ffipublic Fork 0
ad0ccdab6e9bda61631966b5d85747e3e6d533db
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Initial commit: V -> Flutter FFI plugin ad0ccda · on ad0ccdab6e9bda61631966b5d85747e3e6d533db · nandi · 7h ago
memory_check.dart · 21 lines · 856 BDart Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
int rss() => int.parse(File('/proc/self/status').readAsLinesSync()
    .firstWhere((l)=>l.startsWith('VmRSS')).split(RegExp(r'\s+'))[1]);

void main(){
  final lib = DynamicLibrary.open('libvflutter.so');
  final greet = lib.lookupFunction<Pointer<Utf8> Function(Pointer<Utf8>),
      Pointer<Utf8> Function(Pointer<Utf8>)>('vf_greet');
  final vfree = lib.lookupFunction<Void Function(Pointer<Void>),
      void Function(Pointer<Void>)>('vf_free');

  // Regression guard for the -gc none ownership rule: RSS must stay flat.
  final arg = 'fixed'.toNativeUtf8();
  for (var i=0;i<5000;i++){ vfree(greet(arg).cast()); }
  final before = rss();
  for (var i=0;i<900000;i++){ vfree(greet(arg).cast()); }
  print('native-only  before: $before kB  after: ${rss()} kB');
  calloc.free(arg);
}