public static partial class MemoryMarshal
{
public static object GetOwner(ReadOnlyMemory<T> readOnlyMemory)
}
With Registered IO; when sending an receiving data the api doesn't use address, offset, length; it uses id, offset, length
The ids are assigned upfront when you register the addresses (once)
Currently you have to loop through all the registered memory blocks to find which one matches and then get its id which is inefficient and also has to protect against concurrency of new memory being registered while its searching.
This search and registration blocking could be avoided with the new api
if (GetOwner(readOnlyMemory) is RioMemoryPoolBlock block)
{
var idToUse = block.Id;
}
else
{
// Not registered memory, get registered memory block and copy data
}
/cc @davidfowl @KrzysztofCwalina
Nice this could aid in future APIs as well such as append that might only work if the buffer is from the same pool. Or might just avoid a copy
I think it's a reasonable API to add. Let's discuss it at the API review (possibly today).
@terrajobst, @ahsonkhan, @joshfree
You could just return Owner; then if its string or T[] you can do pattern matching on object
We believe this API would slightly better and would be more consistent:
C#
namespace System.Runtime.InteropServices
{
public static class MemoryMarshal
{
public static bool TryGetOwnedMemory<T, TOwner>(ReadOnlyMemory<T> readOnlyMemory, out TOwner ownedMemory)
where TOwner: OwnedMemory<T>;
public static bool TryGetOwnedMemory<T, TOwner>(ReadOnlyMemory<T> readOnlyMemory, out TOwner ownedMemory, out int index, out int length)
where TOwner: OwnedMemory<T>;
}
}
Could do object for pattern matching
public static partial class MemoryMarshal
{
public static object GetOwner(ReadOnlyMemory<T> readOnlyMemory, out TOwner owner,
out int offset, out out lengthy)
public static bool TryGetOwner<T, TOwner >(ReadOnlyMemory<T> readOnlyMemory, out TOwner owner,
out int offset, out out length)
}
This needs to be implemented and merged by 2/28, otherwise it might not make it into 2.1.
Also, I am setting the label to up for grabs :-)
Just writing tests :)
that was quick :-) I thought you would follow TDD: write tests today, run them tomorrow, and then implement the feature on Thursday.
Nice! Now we get that hack out of the RIO memory pool
Is still open; coreclr closed it; still need the corefx part merged. The process to follow :)
Is in now though 馃槃