Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Shockwave on August 24, 2006

Title: What is the fastest way of copying one array to another?
Post by: Shockwave on August 24, 2006
Here's what I want to do.
I want to work in 800 X 600 resolution, usually I'll just use the erase command to clear my screen array which seems to be pretty quick, however I am thinking that it would be nice to have a template 800 * 600 array and when I clear the screen array, I clear it out with the contents of the template array.

This would mean that I could for instance draw the logo on the template array and as long as the procedure to copy the array over was fast enough I could also calculate a nice background to go behind it all.

So basically it's copying the contents of one 800 * 600 Uinteger array into another uinteger array of identical proportions.

The easy way of doing it is a simple loop but this steals fps.
I've looked at Clear, for example;

declare sub CLEAR(byref dst as any, byval value as integer = 0, byval bytes as integer)

CLEAR BYREF Array(1), 0, LEN(Array(1)) * UBOUND(Array)

But that isn't really what I am looking for as it fills the array with a solid colour.
Is there something I am missing here?
Could this be done quicker with inline asm?
If so, how would I do it, my PC Asm skills are nil!
Title: Re: What is the fastest way of copying one array to another?
Post by: Blitz Amateur on August 24, 2006
I'm not sure where you'd find it, but if you look through some of the windows headers, you may be able to find the memcpy function. If you can find that, you should be able to do what you're trying to do =)
Title: Re: What is the fastest way of copying one array to another?
Post by: Jim on August 24, 2006
Use

memcpy(dst, src, length_in_bytes)

from

crt.bi

Code: [Select]
#include "crt.bi"

dim array1(10) as integer
dim array2(10) as integer

for x = 0 to 10
array1(x)=x
next

memcpy(@array2(0), @array1(0), 11*sizeof(integer))

for x= 0 to 10
print array2(x)
next
end

Jim
Title: Re: What is the fastest way of copying one array to another?
Post by: Shockwave on August 25, 2006
Neat! Thanks Chris, Thanks Jim :) That's just what I needed.
Title: Re: What is the fastest way of copying one array to another?
Post by: psygate on September 03, 2006
maybe, don't know whether its working or not, but just try to

put array2,,array1 :whack:
Title: Re: What is the fastest way of copying one array to another?
Post by: Shockwave on September 03, 2006
That ought to work :) Thanks Psygate. Is it any faster?
Title: Re: What is the fastest way of copying one array to another?
Post by: relsoft on September 05, 2006
maybe, don't know whether its working or not, but just try to

put array2,,array1 :whack:

Nope, won't work. Put needs 4 bytes of headers per array, and if he's copying a generic array, things could get nasty. Jim's way is far safer and is as fast.