Caller.TryGetMemorySpan#219
Conversation
0566488 to
3b627f7
Compare
|
I presented this initially as one possible option, but for now I'd prefer to merge this if there are no objections? I might do the other alternative in the future, but it's a huge amount of work which I don't want to commit to at the moment. |
|
I'll get this reviewed shortly, sorry for the wait. |
peterhuene
left a comment
There was a problem hiding this comment.
Looks good 👍. Thanks for adding this.
One thing we can fix up on a follow-up PR is to expand the stackalloc conversion of the name string to the GetMemory and GetFunction methods as well.
We may also want to investigate changing Memory (and other store-related types) to value types too.
That's essentially the other option that I was suggesting (that would be a lot more work than this). My thought was we'd add a |
|
I'm not too concerned with breaking the API when it makes sense to do so (we're rev'ing major versions to match Wasmtime's release numbers anyway); I think we should take the approach that makes the most sense for the API first and foremost; put another way, have good reason to break the API, but not be beholden to compatibility. If we don't want to have to introduce an additional type for accessing a memory, given that the store related types currently implement the Definitely worth looking into, at least. Happy to take either approach. |
|
Ah I was thinking |
| public bool TryGetMemorySpan<T>(string name, long address, int length, out Span<T> result) | ||
| where T : unmanaged | ||
| { | ||
| var nameLength = Encoding.UTF8.GetMaxByteCount(name.Length); |
There was a problem hiding this comment.
It seems you reverted back to the previous approach of using GetMaxByteCount when doing the force-push, was this deliberate? (Sorry for not catching this earlier).
Thanks!
There was a problem hiding this comment.
No it wasn't! I'm not sure quite how I managed that, I'll put in a PR to fix it now. Thanks for catching it 👍
This is one possible way to get access to
Memoryfrom a caller without any allocations. I think this is the simplest option (it's just one method) but the downside it doesn't give access to all of the convenience methods that are onMemory.The other alternative I have come up with is to define a whole new
struct Memorywhich has some/all of theMemorymethods on it and theclass Memorywould just become a wrapper around that. That's a much bigger change though!Thoughts?