Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vm/ffi] Remove memory management from API #38520

Closed
sjindel-google opened this issue Sep 23, 2019 · 13 comments
Closed

[vm/ffi] Remove memory management from API #38520

sjindel-google opened this issue Sep 23, 2019 · 13 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Milestone

Comments

@sjindel-google
Copy link
Contributor

Presently, the Pointer class contains wrappers for malloc and free.

However, we should consider a more neutral position on memory management. It doesn't makes sense to expose these as primitives in WebAssembly, and we can already implement them in Dart.

We can:

  1. Remove Pointer.allocate and Pointer.free and move them to package:ffi.
  2. Introduce an Allocator API, e.g.:
class Allocator {
  Pointer<Void> allocate(int bytes);
  void deallocate(Pointer<Void> memory);
}

However, the Allocator API should arguably live in package:ffi anyway. That would facilitate using dependency injection to mock or replace the allocator and implement different allocation strategies.

@sjindel-google sjindel-google added library-ffi area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Sep 23, 2019
@sjindel-google
Copy link
Contributor Author

/cc @mkustermann @dcharkes

If we change this, we would probably do it before the next release or we risk breaking all our users.

@dcharkes
Copy link
Contributor

Yeah, good idea. Would you like to make a design for this that we could discuss?

If we change this, we would probably do it before the next release or we risk breaking all our users.

Definitely. Even though we're really explicit on that this is an experimental feature and that the API might/will change, I agree that it's important to prioritize things that change the API.

/cc @mraleph @mit-mit

@mkustermann
Copy link
Member

Instead of removing it immediately, we can also mark it as @deprecated for some time, which will show up in the editor and would give people time to transition.

@sjindel-google
Copy link
Contributor Author

My design is just that we remove Pointer.allocate and Pointer.free from our API.

@dcharkes
Copy link
Contributor

My design is just that we remove Pointer.allocate and Pointer.free from our API.

Does this have impact on user code besides changing allocate and free to be looked up through lookupFunction?

@sjindel-google
Copy link
Contributor Author

Not as far as I know.

@dcharkes
Copy link
Contributor

This would make the following 3 issues obsolete:

@mkustermann
Copy link
Member

We should ensure we can find the right malloc and free on all platforms. Then I don't see any reason why we shouldn't move ahead with this.

@sjindel-google sjindel-google self-assigned this Sep 23, 2019
@sjindel-google
Copy link
Contributor Author

It turns out that using malloc and free is already broken on Windows, because we statically link CRT (at least the standalone embedder does):

https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019#what-problems-exist-if-an-application-uses-more-than-one-crt-version

We must either remove Pointer.allocate/Pointer.free or re-wire them to HeapAlloc/HeapFree.

@sjindel-google
Copy link
Contributor Author

allocate and free have been deprecated and their replacements are available in package:ffi.

We just need https://github.com/dart-lang/tflite_native/pull/29/files to land before we can remove them entirely.

@mkustermann
Copy link
Member

The PR for package:tflite_native has landed. Can we then remove those deprecated functions?

@sjindel-google
Copy link
Contributor Author

This is blocked on non-generic structs in the SDK, since we need to roll the latest package:ffi and package:tflite_native to fully remove the deprecated methods.

@dcharkes
Copy link
Contributor

We can remove all deprecated methods together, tracked in issue #38860.

I'll create a CL that removes all of them. (Unless you already have a CL to remove the memory management ones @sjindel-google?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

3 participants