createSession method

Pointer<OrtStatus> createSession({
  1. required Pointer<OrtEnv> env,
  2. required String modelPath,
  3. required Pointer<OrtSessionOptions> sessionOptions,
  4. required Pointer<Pointer<OrtSession>> session,
})

Implementation

Pointer<OrtStatus> createSession({
  required Pointer<OrtEnv> env,
  required String modelPath,
  required Pointer<OrtSessionOptions> sessionOptions,
  required Pointer<Pointer<OrtSession>> session,
}) {
  final createSessionFn =
      CreateSession.asFunction<
        Pointer<OrtStatus> Function(
          Pointer<OrtEnv>,
          Pointer<Char>,
          Pointer<OrtSessionOptions>,
          Pointer<Pointer<OrtSession>>,
        )
      >();
  final modelPathChars = Platform.isWindows
      ? modelPath.toNativeUtf16().cast<Char>()
      : modelPath.toNativeUtf8().cast<Char>();
  try {
    final status = createSessionFn(
      env,
      modelPathChars,
      sessionOptions,
      session,
    );
    return status;
  } finally {
    malloc.free(modelPathChars);
  }
}