11-23-2005, 08:28 AM
Pages: 1 2
11-23-2005, 10:23 PM
If you just need to use the same data without modifying it, then you could use a pointer.
Anonymous
11-24-2005, 12:42 AM
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
11-24-2005, 01:04 AM
To clarify, Torahteen,
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
you need to use
len(byte) * 20
(remember the 0th subscript)
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)
11-24-2005, 07:28 AM
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 >)
11-24-2005, 08:18 AM
Yo! Syn! Hows ZGA coming :)
The newest pics of the ships are... stunning.
The newest pics of the ships are... stunning.
11-24-2005, 09:10 AM
Quote:...
So if you have the array
you need to use len(byte) * 20Code:dim blarg(19) as byte
(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
11-24-2005, 09:35 AM
Or you can use the fast MMX copy sub from the gfx library.
Joshy
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
11-24-2005, 05:03 PM
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.
11-24-2005, 05:31 PM
Exactly. In C is the way you say. That's 'cause of this:
In C:
In BASIC:
The semantics are different.
In C:
Code:
int a[number-of-subscripts];
In BASIC:
Code:
Dim a (highest-subscript) As Integer
The semantics are different.
Pages: 1 2