S
Saga
Hello all, I am migrating a VB6 module to VB 2008. This module makes
use of the UBound and LBound functions to determine array bounds. I
left them as is and they worked fine in VB2008. I am aware that VB'08
has the GetUpperBounds() method, but I can't seem to find if there are
any downsides to leaving the U/LBound() functions as is or if I should
change these to the newer method. Is there any advantage/disadvantage
to this?
Also, since the arrays are large, the VB6 code is using the Windows
API CopyMemory to transfer data quickly. I found that in VB2008
(and some previous .NET versions, I assume) I can do this:
Buffer.BlockCopy(Source, SrcOff, Dest, DestOff, Length)
This works. Is this the best and fastest method to transfer data
from one large array to another (arrays can be 100K in size).
I also see that some use the following:
Array.Copy(srcAr, destAr, Length)
Any advantage of one method over the other? In my case, I
sometimes have to copy an array into an offset of the other, for
example something equivalent to the following:
SomeData is array previously dimensioned and containing data
ReDim Array2(UBound(SomeData) + 2)
For iIdx = 2 To Array2.GetUpperBound(0)
Array2(iIdx) = SomeData(iIdx - 2)
Next iIdx
I do this with Buffer.BlockCopy:
Buffer.BlockCopy(SomeData, 0, Array2, 2, UBound(SomeData))
I am not sure I can do this with Array.Copy. Thanks all! Saga
use of the UBound and LBound functions to determine array bounds. I
left them as is and they worked fine in VB2008. I am aware that VB'08
has the GetUpperBounds() method, but I can't seem to find if there are
any downsides to leaving the U/LBound() functions as is or if I should
change these to the newer method. Is there any advantage/disadvantage
to this?
Also, since the arrays are large, the VB6 code is using the Windows
API CopyMemory to transfer data quickly. I found that in VB2008
(and some previous .NET versions, I assume) I can do this:
Buffer.BlockCopy(Source, SrcOff, Dest, DestOff, Length)
This works. Is this the best and fastest method to transfer data
from one large array to another (arrays can be 100K in size).
I also see that some use the following:
Array.Copy(srcAr, destAr, Length)
Any advantage of one method over the other? In my case, I
sometimes have to copy an array into an offset of the other, for
example something equivalent to the following:
SomeData is array previously dimensioned and containing data
ReDim Array2(UBound(SomeData) + 2)
For iIdx = 2 To Array2.GetUpperBound(0)
Array2(iIdx) = SomeData(iIdx - 2)
Next iIdx
I do this with Buffer.BlockCopy:
Buffer.BlockCopy(SomeData, 0, Array2, 2, UBound(SomeData))
I am not sure I can do this with Array.Copy. Thanks all! Saga