Most efficient way to xor byte array in vb.net

核能气质少年 提交于 2019-12-10 21:56:39

问题


I am making making an application in vb.net that will read files using a byte array as buffer, and create parity files for them by xoring the data... What would be the most efficient way of xoring a byte array? I have though of convertinbg the byte array to a bitarray and then run it trough an xor operation and turn it back to a byte array, but that sounds like a very processing expensive task, and i am worried that it might impact read/write speed... is there a better way to do this? thanks...

To avoid confusion: What the application does is read half the file to location 1, the other half to location 2, then a parity (xor of the two parts) to location 3...


回答1:


To Xor two byte arrays simply use a for loop and the Xor operator.

VB.Net's Xor will compile to a the CIL Xor opcode which should be subsequently JIT compiled to the very fast x86 XOR processor instruction.

The cost of the Xor operation is likely to be negligible in comparison to the cost of file I/O.




回答2:


Depending on what you mean by "efficient" I think you can do better than a simple loop. My initial though is to break the processing into multiple threads. so it will complete faster. You know the size of the input array and therefore the output array so it would be easy to divide load and let each thread fill the appropriate part of the result.

There is a C# article on code project that does similar. Binary operations on byte arrays withparallelism



来源:https://stackoverflow.com/questions/22418898/most-efficient-way-to-xor-byte-array-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!