Hi Dave,

Are you reading your data from a fixed storage (e.g. a file, and not
from a socket) and do you know how much bytes you'd need upfront? If
you do then you can preallocate the buffer w/ the exact size you need,
but I guess you don't know the size upfront. If you don't, then I'd
suggest what a lot of people mentioned already suggested -
MemoryStream, and will just add a StreamWriter on top of it.

If you want to avoid the inevitable resizing which will happen in the
MemoryStream instance, and you don't mind working on scattered data,
just read your data in multiple arrays and just keep track of the real
size of the last array. That's what I'd do if I had to read hundreds
of megabytes of data and don't know the exact size upfront.

Cheers,
Stoyan

On 7/6/06, dave wanta <[EMAIL PROTECTED]> wrote:
hi all,
does anyone know of an efficient way to trim a byte array?

Here is what is happening. I'm reading in some binary data into a
dynamically expanding byte array, until all of the data has been read into
memory. I need to trim the byte array to remove the trailing nulls. Because
the amount of data is large (100megs+), I don't want to simply create a 2nd
100meg+ byte array in memory, and then copy it. So, is there anyway to trim
the existing byte array, and then return it?

Thanks,
Dave

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to