String that points to byte()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a array of Byte received from a socket.

I need to process that array as fast as it's possible, so ideally I should
be able to use the data from that array instead of creating objects from it.

For example, can I create a String object whose contents are stored in that
array? i.e. I don't want to COPY some bytes from the array into a new object,
but rather, create a object that POINTS to some offset in the array.

Thanks.

PS. Any other approach is welcome, too.
 
Carlos Fernandez said:
I have a array of Byte received from a socket.

And what encoding is that text data in?
I need to process that array as fast as it's possible, so ideally I should
be able to use the data from that array instead of creating objects from it.

For example, can I create a String object whose contents are stored in that
array? i.e. I don't want to COPY some bytes from the array into a new object,
but rather, create a object that POINTS to some offset in the array.

Well, you could write your own String-like object which just stores an
offset into a byte array and does decoding when necessary, but you
wouldn't be able to pass that as a string parameter without some
conversion to a real string.

Have you actually determined that decoding the data in the normal way
*is* too slow?
 
Jon,

I see your point.
Anyway we are trying to do it as fast as we are capable of, EVEN if for this
specific case, we could get away with what we have now.
Anyhow, how do I create a String from part of a byte()?. Suppose the
encoding is plain ASCII or some 8 byte format (definitely not unicode).

Thanks.
 
Something like :

Dim by() As Byte = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77}
Dim strn As String = System.Text.ASCIIEncoding.ASCII.GetString(by, 3, 4)

Steven
 
Back
Top