Array copy.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am doing the below code.

for (int n = 0; n < 1000; n++)
buffer[n] = data[FrameNumber, n];

Here, buffer is one dimension int array and data is two dimensions array.

Is there any better way to copy from two dimensions array to one dimension
array
in performance perspective?

Thanks,
 
Back said:
Hello,

I am doing the below code.

for (int n = 0; n < 1000; n++)
buffer[n] = data[FrameNumber, n];

Here, buffer is one dimension int array and data is two dimensions array.

Is there any better way to copy from two dimensions array to one dimension
array
in performance perspective?

Thanks,

The only thing I can think of is to change data to be a jagged array.
I'm not sure what else your code is doing, but then you could do:

int[][] data = new int[numberOfFrames];
for (int i=0; i<numberOfFrames; i++)
data = new int[capacity];

And then:

int[] buffer = data[FrameNumber];

If that doesn't work due to whatever else your code is doing, then I
think you're doing the best thing possible.

Hope this helps.

Dan Manges
 
Hi!

I think, buffer.blockcopy is your friend
try :

Dim a1(,) As Integer = {{1, 1}, {1, 2}}

Dim a2(3) As Integer

Buffer.BlockCopy(a1, 0, a2, 0, 4 * 4)

' 4 elements * 4 Bytes for each integer

For i As Integer = 0 To 3

Debug.Print(a2(i).ToString)

Next i
 
Oops, VB.Net , but you will get the idea


wolfgang

Wolfgang Hauer said:
Hi!

I think, buffer.blockcopy is your friend
try :

Dim a1(,) As Integer = {{1, 1}, {1, 2}}

Dim a2(3) As Integer

Buffer.BlockCopy(a1, 0, a2, 0, 4 * 4)

' 4 elements * 4 Bytes for each integer

For i As Integer = 0 To 3

Debug.Print(a2(i).ToString)

Next i

Back 9 said:
Hello,

I am doing the below code.

for (int n = 0; n < 1000; n++)
buffer[n] = data[FrameNumber, n];

Here, buffer is one dimension int array and data is two dimensions array.

Is there any better way to copy from two dimensions array to one
dimension
array
in performance perspective?

Thanks,
 
Back
Top