Method for fast array arithmetic?

com , arrays optimisation , Sydney, Australia
  • 8 years ago
    Hi, I have a simple challenge whose solution is proving elusive. Two one-dimensional byte arrays of equal length need to have a mathematical operation performed on their respective elements. The code is like this: Dim aNumbers1(10000) As Byte Dim aNumbers2(10000) As Byte Dim aResult(10000) As Byte For iCounter As Integer = 9999 to 0 step -1 aResult(iCounter) = Math.Max(aNumbers1(iCounter), aNumbers2(iCounter)) Next ...but of course this is horribly slow. Are there any P/Invokes or COM tricks that could achieve this in a more efficient way? I tried BlockCopy to arrays of UInt32 but it made no noticable difference. Thanks!
  • 8 years ago
    EDIT: The BlockCopy was actually related to a bitwise OR operation, but max/min/add/sub are some other operations I need to do as well. Note the +/- need to stop at max/min values rather than wrapping around. Thanks.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry