locked
What is the fastest way to modify a byte array? RRS feed

  • Question

  • 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 modify that array of bytes? note that read read thing is already done i only need to know a fastest way to modify my bytes array, only that............ thanks in advance
    Friday, July 8, 2011 1:16 PM

Answers

  • I suspect you have omitted something critical in your question.  Assuming you have a byte array declared as:
     
        byte [] data;
     
    Then this should be as fast as you can hope for:
     
        data [index] = 0x33;

    --
    Mike
    • Marked as answer by Lie You Friday, July 15, 2011 2:44 AM
    Friday, July 8, 2011 11:24 PM
  • At face value, I agree with Family Tree Mike.

    You can make use of pointers in C# in an "unsafe" context, if you allow unsafe code.  This might allow you to save some of the overhead of marshalling your data to and from a byte array.

    But your question worries me because it seems oversimplified.  You mentioned "flash".  Do you mean like a USB flash drive?  Or do you mean some special kind of hardware device?  And when you talk about modifying the bytes, do you mean in system memory or are you talking about a round-trip of reading from a device, modifying in system memory, and then writing back to a device?  Or are you talking about files?

    • Marked as answer by Lie You Friday, July 15, 2011 2:44 AM
    Saturday, July 9, 2011 8:15 AM

All replies

  • I suspect you have omitted something critical in your question.  Assuming you have a byte array declared as:
     
        byte [] data;
     
    Then this should be as fast as you can hope for:
     
        data [index] = 0x33;

    --
    Mike
    • Marked as answer by Lie You Friday, July 15, 2011 2:44 AM
    Friday, July 8, 2011 11:24 PM
  • At face value, I agree with Family Tree Mike.

    You can make use of pointers in C# in an "unsafe" context, if you allow unsafe code.  This might allow you to save some of the overhead of marshalling your data to and from a byte array.

    But your question worries me because it seems oversimplified.  You mentioned "flash".  Do you mean like a USB flash drive?  Or do you mean some special kind of hardware device?  And when you talk about modifying the bytes, do you mean in system memory or are you talking about a round-trip of reading from a device, modifying in system memory, and then writing back to a device?  Or are you talking about files?

    • Marked as answer by Lie You Friday, July 15, 2011 2:44 AM
    Saturday, July 9, 2011 8:15 AM