Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 how to avoid moving data, c#

views
     
TSnarf03
post Mar 16 2024, 01:30 AM, updated 2y ago

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


Lets say you have a byte array, of 1 million items (1 mega byte)

this array will be used to store incoming data from network, and data keep coming in. when enough data arrived, will get processed, but the data will still maintain in the array, just pointer will be moved(indicating where new data should append to and until where it has been processed)

I wonder if there is a way of keep using this 1 mega byte buffer, without moving and manually truncate them.

ie currently reaching the very end of the buffer, at 999,000 bytes i can use another 1k bytes only before i hit out of bound error, are there anyway to lets say dispose the 900k bytes at the front then move them to the end ? i know u can copy whatever relevant to the front then keep using the same buffer, but the indexing will be a bit confusing and copy and move data during that moment will cause slight delay, beside moving those data, any alternative ?
TSnarf03
post Mar 16 2024, 01:39 AM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(SotongBiru @ Mar 16 2024, 01:38 AM)
Do you mean a circular/ring buffer kind?
*
ya, anything like that ?

 

Change to:
| Lo-Fi Version
0.0157sec    0.25    6 queries    GZIP Disabled
Time is now: 24th December 2025 - 03:32 AM