Community discussion forum

Method for fast array arithmetic?

  • 7 months 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!
    Post was edited on 21/04/2009 14:47:11 Report abuse
  • 7 months 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).

We'd love to hear what you think! Submit ideas or give us feedback