Refactor
This commit is contained in:
15
lib/core/utils/ffi_utils.dart
Normal file
15
lib/core/utils/ffi_utils.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
R withMemory<R, T extends NativeType>(
|
||||
int size,
|
||||
R Function(Pointer<T> memory) action,
|
||||
) {
|
||||
final memory = calloc<Int8>(size);
|
||||
try {
|
||||
return action(memory.cast());
|
||||
} finally {
|
||||
calloc.free(memory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user