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

Get Arguments Directly From Pointers #17

Merged
merged 7 commits into from
Jan 6, 2024
Merged

Conversation

vixalien
Copy link
Collaborator

I lacked a better title for this PR :^(

This PR is significant because it implements passing around arguments in their raw pointer form instead of allocating new ArrayBuffers.

This is done by creating a BigUint64Array, passed as an argument to FFI functions (gi_(function|method|callback)_invoke). The FFI functions directly manipulate and set the pointers as indices of the BigUint64Array, and we can get the assigned pointers directly from the BigUint64Array. Here's some pseudocode to explain this:

const array = BigUint64Array(outArgDetails.length);

// the array is initially empty
console.log(array) // [0,0,0,0,....]

// invoke the function with the array as outArgs
g.function_info.invoke(
  function_name,
  //...
  outArgs,
  // ....
);

// now the array has been modified to have pointers
console.log(array) // [28933n, 329839n, 23893495834n, ...]

// now we can use the pointers directly (in the case of numbers, the values are not pointers but the numbers themselves directly

Thanks for taking a look at this.

I also created a new file, examples/bytes.ts, a temporary file to test things out since deno_gi doesn't have actual tests at the moment (I'm working on it...). You can delete this before merging. Thanks!

const outArgs = outArgsDetail.map((d) => initArgument(d.type));

return outArgs;
return new BigUint64Array(outArgsDetail.map((d) => initArgument(d.type)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite correct. I think initArgument should return a pointer to a memory of the size of the interface (if given an interface) and not initialise a new object. Please advise!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about that. If you managed to do it the better way, introduce it in a new PR.

@vixalien
Copy link
Collaborator Author

Maybe it's time to review this next?

examples/bytes.ts Outdated Show resolved Hide resolved
src/types/argument.js Outdated Show resolved Hide resolved
@ahgilak
Copy link
Owner

ahgilak commented Dec 26, 2023

Sorry it's taking so long, I'm a bit busy these days. I'll review this by the end of the week.

@vixalien vixalien mentioned this pull request Dec 26, 2023
@vixalien
Copy link
Collaborator Author

Sorry it's taking so long, I'm a bit busy these days. I'll review this by the end of the week.

Hey! No worries. Take your time, and you don't have to review these ASAP. I just create a PR for every thing I change so the changes don't get lost. Please don't feel pressured to review this and take your time!

@vixalien
Copy link
Collaborator Author

vixalien commented Jan 6, 2024

I've rebased the code and removed the bytes.ts file. I plan to reintroduce plausible tests later.

@vixalien vixalien requested a review from ahgilak January 6, 2024 02:49
@ahgilak ahgilak merged commit 97f83b8 into ahgilak:main Jan 6, 2024
@vixalien vixalien deleted the arguments branch January 6, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants