Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to modify a byte array that I've read from my memory.... a need to modify it an then rewrite to my flash all it again..but i need to do it faster.. what is the fastest way to do that?............ thanks in advance

My code:

byte []array1 = {3,4,2};
byte[] mybufferarry = ReadArrayFromFile();
int k = 0;
for(int i = 5 ; i < 3 ; i++)
    mybufferarray[i] = array1[k++];
Posted
Updated 8-Jul-11 4:32am
v2
Comments
harish85 8-Jul-11 10:39am    
5<3 ?

How can we possibly answer this with the information you've given us?

EDIT ================

Your sample sucks. The loop you specified won't have any effect on mybuffarray because you're starting the loop at 5, and going until the loop is 3, and INCREASING the loop control variable.
 
Share this answer
 
v2
Comments
glbrt.gds 8-Jul-11 9:42am    
sorry ......... i only need to know how to modify my array of bytes the other work is already done...I've read already the bytes and etcc..... "only need to know if is there a way to modify my array no using the common for(int i = 5 ; i++) bytearray[i] = otherarray[k++];
S Houghtelin 8-Jul-11 9:54am    
Perhaps you are already doing it the fastest way that it can be done, without seeing the code we cannot help you.

Please update your question, "etc. etc." is not valid syntax.
If you know the specific bytes you wish to change then just set them using bytearray[x] = value directly. If the byte array is very large and you do not want to iterate through each item in the list then you could create an update dictionary with an index and new value. Then you just have to iterate through the dictionary changing only the bytes necessary.

Based on your code snippet, you have bigger issues that you think.
There is no way that your for loop will ever execute anything. You initialize i to 5 and only run if it is less than 3. How is that going to work? Fix your for loop first and then try debugging again.
 
Share this answer
 
v2
Comments
glbrt.gds 8-Jul-11 10:50am    
Marcus you are rigth,I just wrote it by memory and the loop condition is bad as you said........but do you think that is one of the correct ways to do that? I mean. one of fastest..?
glbrt.gds 8-Jul-11 10:55am    
Someone has told me about Buffer.BlockCopy
Can you use Memory Mapped Files[^] (.Net 4)?

Without knowing more about your problem it is impossible to answer. Direct indexed access to a byte array in memory should be fast enough, I strongly suspect (particularly given your inability to provide a working for loop in your sample) that any speed problems you are having are elsewhere in your code.
 
Share this answer
 
Comments
glbrt.gds 8-Jul-11 12:52pm    
sorry but...I don't know what else do you need to know..I'm just wondering if are there some others ways to modify a byte array...just that...the error on my sample (in my loop) was just a writing error posting it... just that, it is not an error that I've in my real code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900