Fast array copy

Posted By: RyuMaster

Fast array copy - 12/10/08 13:20

Hi!
I have two large arrays to store level data, and I need to copy one to another on every frame cycle.
Quote:

for (k = 0; k < 1350; k++)
{
for (i = 0; i < 1350; i++)
{



maparray2[i][k][0] = maparray[i][k][0];
maparray2[i][k][1] = maparray[i][k][1];
maparray2[i][k][2] = maparray[i][k][2];

}
}


But this kills a lot of CPU, maybe someone knows of faster/better way to code such array-to-array copying?

Regards,
Konstantin.
Posted By: ventilator

Re: Fast array copy - 12/10/08 13:23

how about memcpy()? but why do you need to copy the array each frame?
Posted By: kasimir

Re: Fast array copy - 12/10/08 13:26

this are 5 million Array-Elements!! (5467500)
i think that would be kill every PC...

try to find a better way than this!
Posted By: RyuMaster

Re: Fast array copy - 12/10/08 13:57

Eeem... My map is divided into many cells. Every cells holds information which is loaded on level start once (from image using colors), into maparray massive; This array is constant.

(maparray[Xcellposition][Ycellpositon][colorRED])
(maparray[Xcellposition][Ycellpositon][colorBLUE])
(maparray[Xcellposition][Ycellpositon][colorGREEN])

On top of it, every frame some entities are moving. Every entity also has its "map-cell" representation. So, I copy maparray to maparray2, add entity dynamic cell info to maparray2 then, and pass this complete map information for further pathfindings and interactions.


I never used memcpy(), is it safe and easy to play with it?
Posted By: RyuMaster

Re: Fast array copy - 12/10/08 14:07

1350 is absolute maximum, i think 700-800 will be maximum, but I want to deal with extreme case first
Posted By: Joey

Re: Fast array copy - 12/10/08 14:19

just a suggestion: store it in a bitmap, since you only have red, green and blue information this would work best. use bitblt to copy the bitmap. for direct access of the bitmap information, you can retreive the pointer to the bitmap data and access it dependent on the format and size of the bitmap. it's some pointer arithmetics but definately fast and viable.
Posted By: RyuMaster

Re: Fast array copy - 12/10/08 14:59

Hi, Joey!
I was thinking of that at the start. I created bitmap for leveldata. And bitmap panels for entities.

Then I found out, that I can not perform pixel operations on panels.
If I render panel to target, this target can not be locked.
And I can not use only BMAPs for storing data. I need panels, to move BMAP along with entity when it moves. And there are also many problems. The worst one - all pixel operations are very slow.

But I always consider this idea in my head, it is just too hard for me to find performant solution.
Posted By: RyuMaster

Re: Fast array copy - 12/10/08 15:00

>>for direct access of the bitmap information<<
Or You mean something else by this? Not pixel-read access?
Posted By: Joey

Re: Fast array copy - 12/10/08 17:55

i'm not quite sure what you're trying to accomplish. if you could be somewhat more precise i think we can help you.
© 2024 lite-C Forums