10-29-2005, 03:54 PM
I never really understood pointers until I started using them
i'll try my best to explain them, though
basically, everything in the computer memory has an address of some sort, yes?
Well, a pointer is used to find that address.
So, instead of moving a chunk of memory from place to place, we can just send the address, and any variable can use this address
for example
Ah-ha....we have a variable....not comes the fun part:
now we have data in the variable.......instead of tranporting the 123456 value, we can transfere the address:
The '@' symbol retrieves the pointer address of the variable....so note that example and @example are two completely different numbers
How is this helpful?
you can use this for a few different things:
copying a variable
this comes in handy, severly, when you have huge amounts of data in a UDT (user defined type)
If you are dealing with pointers of a UDT, instead of using a period to use a sub-variable, use the -> sign (minus + greater-than)
Pointers are mainly used because with addresses, you can do some 'fun' things when you really get a handle on them ( cptr().... :rotfl: )
hope that helps the explaination
oz~
i'll try my best to explain them, though
basically, everything in the computer memory has an address of some sort, yes?
Well, a pointer is used to find that address.
So, instead of moving a chunk of memory from place to place, we can just send the address, and any variable can use this address
for example
Code:
DIM example AS INTEGER
Ah-ha....we have a variable....not comes the fun part:
Code:
example = 123456
Code:
PRINT example, @example
The '@' symbol retrieves the pointer address of the variable....so note that example and @example are two completely different numbers
How is this helpful?
you can use this for a few different things:
copying a variable
Code:
DIM example2 AS INTEGER
example2 = @example ' Now, when example changes, example2 will change, because it uses the same memory
this comes in handy, severly, when you have huge amounts of data in a UDT (user defined type)
Code:
TYPE some_example
a as string * 50
b as long
c(100) as integer
END TYPE
DIM example3 as some_example
dim cnt as integer
example3.a = string$(50, chr$(int(rnd * 255)))
example3.b = 329465084765447
for cnt = 1 to 100
example3.c(cnt) = int(rnd * 100)
next
'(...)
SUB test(exptr as some_example ptr)
print exptr->a
print exptr->b
print exptr->c
END SUB
If you are dealing with pointers of a UDT, instead of using a period to use a sub-variable, use the -> sign (minus + greater-than)
Pointers are mainly used because with addresses, you can do some 'fun' things when you really get a handle on them ( cptr().... :rotfl: )
hope that helps the explaination
oz~