labstreaminglayer / liblsl-Csharp

C# bindings for liblsl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pull_chunk issue

jdevoldere opened this issue · comments

pull_chunk requires you to pass in a data buffer and timestamp buffer by reference.
You must initialize these buffers before pulling the chunk but how can you do so without knowing the size of the chunk beforehand?

During the creation of the inlet you specify the maximum chunk size: https://github.com/labstreaminglayer/liblsl-Csharp/blob/master/LSL.cs#L495-L499

Then you can pre-allocate a buffer of this size to pass to pull_chunk.

pull_chunk returns the number of samples it actually wrote, so you can then use that information to slice the buffer to the appropriate size.

Depending on your program architecture, you may wish reuse the pre-allocated buffer (e.g., make it a member variable of a class instance) to save time on memory allocation. If you do that, be careful of how you pass the slice of data around for subsequent processing. If you have some things happening in parallel and you don't want to worry about colliding access to the data then you should probably return a copy of a slice of the buffer. This is still more efficient than pre-allocating the full buffer on every iteration because the slice is probably going to be much smaller than the full buffer.

I'll close this issue because I'm confident this answers your original question. We can continue to discuss if you wish.