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

Memory data "bufferMem" changes when the GC.AllocatedArray data changes... #6

Open
Chroma72 opened this issue Jun 22, 2022 · 2 comments

Comments

@Chroma72
Copy link

Chroma72 commented Jun 22, 2022

In the example you are only recording the received bytes to show throughput. But how do you utilize the received data before the next datagram comes in and changes the GC array which changes the Memory span? The memory "bufferMem" is linked to the GC array and is ever-changing. You would have to copy the received data to a different type to preserve the received data so it can be used later. How did you tackle this with no allocation and no copying?

Thanks for your time and I'm looking forward to your reply.

@Touseefelahi
Copy link

@Chroma72 Allocate a big Memory chunk in the start and then use slices to receive the data in the buffer

while (Camera.IsStreaming)
{
    var reply = await socketRxRaw.ReceiveFromAsync(bigBuffer.Slice(StartIndex, ExpectedSize), SocketFlags.None, new 
    IPEndPoint(IPAddress.Any, Camera.PortRx));
    StartIndex+=reply.ReceivedBytes;
   If(SomeCondition)
  {
    ProcessData(bigBuffer);
  }
}

Process the data at once
`

@Chroma72
Copy link
Author

Chroma72 commented Nov 17, 2022

Hello and thanks for the reply. But if you wanted to put the received data into a queue to be consumed later, then this is not the desired model. Any idea on how to use the data later and still not have allocations.

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

No branches or pull requests

2 participants