Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copying Contents of an Array without Loop?
#1
Is there a way to do this?
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#2
If you just need to use the same data without modifying it, then you could use a pointer.
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Reply
#3
Code:
#include "crt.bi"

dim r( 3 ) as integer
dim p( 3 ) as integer


r( 0 ) = 7
r( 1 ) = 3
r( 2 ) = 3
r( 3 ) = 1

memcpy( @p( 0 ), @r( 0 ), len( integer) * 4 )

for ui = 3 to 0 step - 1

  ? p( ui )

next
sleep
Reply
#4
To clarify, Torahteen,

Quote:
Code:
memcpy( @p( 0 ), @r( 0 ), len( integer) * 4 )

memcpy is included in the C runtime library, so you have to include crt.bi and compile with the crt lib.

the last argument must be len(datatype) * number of subscripts

So if you have the array

Code:
dim blarg(19) as byte

you need to use

len(byte) * 20

(remember the 0th subscript)
Reply
#5
bwah! i was trying to find something like that, i was thinking to myself 'isnt there a memcopy routine or something like that...' but i couldnt find it... and that explains why, heh, its c >)
Reply
#6
Yo! Syn! Hows ZGA coming :)

The newest pics of the ships are... stunning.
Reply
#7
Quote:...
So if you have the array
Code:
dim blarg(19) as byte
you need to use len(byte) * 20

(remember the 0th subscript)

Code:
dim array(20) as byte = index 0 to 19 = 20 bytes
'but
dim array(19) as byte = index 0 to 18 = 19 bytes
'or
dim dim array(1 to 20) as byte = index 1 to 20 = 20 bytes

Or i'm wrong ?

Joshy
sorry about my english
Reply
#8
Or you can use the fast MMX copy sub from the gfx library.

Joshy
Code:
#include "fbgfx.bi"
declare sub mmxcopy alias "fb_hMemCpyMMX" (byval dest as any ptr, byval src as any ptr, byval size as integer)

const MB =1024*1024

dim source(MB) as byte
dim destination(MB) as byte
dim i as integer
for i=0 to MB-1
  source(i)=rnd*255
next

print "begin copy 250 MB"
for i=1 to 250
  mmxcopy @destination(0),@source(0),MB
next
print "ready"
sleep
sorry about my english
Reply
#9
Quote:
Code:
dim array(20) as byte = index 0 to 19 = 20 bytes

If you dimension an array using (20), it will dimension index 0 to 20, giving 21 subscripts.
Reply
#10
Exactly. In C is the way you say. That's 'cause of this:

In C:

Code:
int a[number-of-subscripts];

In BASIC:

Code:
Dim a (highest-subscript) As Integer

The semantics are different.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)