Alex Rivera | Logout

How to split a byte array

Asked 2008-08-21T19:01:28.043
40

I have a byte array in memory, read from a file. I would like to split the byte array at a certain point (index) without having to just create a new byte array and copy each byte at a time, increasing the in memory foot print of the operation. What I would like is something like this:

byte[] largeBytes = [1,2,3,4,5,6,7,8,9];  
byte[] smallPortion;  
smallPortion = split(largeBytes, 3);  

smallPortion would equal 1,2,3,4
largeBytes would equal 5,6,7,8,9

Edit
Report

1 Answer

0

You can't. What you might want is keep a starting point and number of items; in essence, build iterators. If this is C++, you can just use std::vector<int> and use the built-in ones.

In C#, I'd build a small iterator class that holds start index, count and implements IEnumerable<>.

answered 2008-08-21T19:09:13.173

Your Answer