خرید بک لینک

Vote count: 0

I have a TCP stream coming in and it fills up a 256 byte[].

From there I process the byte array parsing out messages etc.

Once I get to < 100 bytes in the first array, I want to take the remaining bytes add them to a new array and then append the new 256 byte array and continue processing so I don't miss messages.

    public static byte[] Combine(byte[] first, byte[] second)
    {
      byte[] ret = new byte[first.Length + second.Length];
      Buffer.BlockCopy(first, 0, ret, 0, first.Length);
      Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
      retu ret;
    }        

I'm using this function (Taken from one of Jon Skeet's post) however there is an issue that happens in that the byte[] continually gets bigger.

For example if I have buffer[] that is 256 and newbuff[] 256 and pass it to the function above...I get back a ret of 512[].

Now if I pass the Combine function again it adds on the 256 to the 512 and continuously grows causing a bit of an issue as I am processing a rather large tcp data feed.

Any suggestions on how to make this more efficient? Currently I have tried using this variation but it seems like I am caught in a circle.

    public static byte[] Combine(byte[] first, byte[] second, int srcOffset)
    {
     byte[] ret = new byte[first.Length -srcOffset + second.Length];
     Buffer.BlockCopy(first, srcOffset, ret, 0, first.Length - srcOffset);
     Buffer.BlockCopy(second, 0, ret, first.Length - srcOffset, second.Length);
     retu ret;
   }

Thanks in advance guys!

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 19 خرداد 1395 ساعت: 3:55

صفحه بندی