Author Topic: What is the fastest way of copying one array to another?  (Read 4107 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
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!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Blitz Amateur

  • Atari ST
  • ***
  • Posts: 243
  • Karma: 13
    • View Profile
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 =)

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
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
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Neat! Thanks Chris, Thanks Jim :) That's just what I needed.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline psygate

  • Completly Insane.
  • Atari ST
  • ***
  • Posts: 173
  • Karma: 7
  • That boy needs therapy.
    • View Profile
Re: What is the fastest way of copying one array to another?
« Reply #4 on: September 03, 2006 »
maybe, don't know whether its working or not, but just try to

put array2,,array1 :whack:
He who controlles the minds commands the many.
He who commands the many, conqueres the minds.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: What is the fastest way of copying one array to another?
« Reply #5 on: September 03, 2006 »
That ought to work :) Thanks Psygate. Is it any faster?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: What is the fastest way of copying one array to another?
« Reply #6 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.
Challenge Trophies Won: