-
Notifications
You must be signed in to change notification settings - Fork 347
Remove TryGetPointer from RioTcpConnection #1375
Conversation
I think that looks good /cc @davidfowl |
@KodrAus You need to call Free so the ref count doesn't just go up forever. |
@davidfowl Derp. Fixed. That's a nice segway into there are no tests for any of this code. Looks like the |
@@ -116,6 +116,23 @@ public IntPtr GetBufferId(IntPtr address, out long startAddress) | |||
return id; | |||
} | |||
|
|||
public unsafe RioBufferSegment GetSegmentFromMemory(Buffer<byte> memory) | |||
{ | |||
var pin = memory.Pin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment about why it's ok to unpin here because the memory needs to be pinned already? How do we enforce that though? There's no way to know if the backing memory is already pinned...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But since we create the pool, it's ok. Just add the comment and I'll merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How's that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Part of #1298
Moves the
GetSegmentFromMemory
method into theRioThread
and usesPin
instead ofTryGetPointer
. I think it's safe to not keep theMemoryHandle
around because we verify the memory is from aSlab
in the memory pool using its address, which we know is pinned.So now it's
RioThread
s responsibility to make sure its buffers are pinned, which is better because it's the one creating theMemoryPool
.I'm not sure about error handling, if it turns out the memory isn't from a known slab then the RIO buffer id is
IntPtr.Zero
, but we're not explicitly dealing with this.