Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Anyone interested in making a text adventure as a group?
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
Code:
DIM example AS INTEGER

Ah-ha....we have a variable....not comes the fun part:

Code:
example = 123456
now we have data in the variable.......instead of tranporting the 123456 value, we can transfere the address:
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~
Reply


Messages In This Thread
been thinkin - by zoasterboy - 10-22-2005, 10:54 AM
sorry! - by phycowelder - 10-23-2005, 12:13 PM
before... - by zoasterboy - 10-24-2005, 07:43 AM
story line - by zoasterboy - 10-25-2005, 04:47 AM
yah - by zoasterboy - 10-25-2005, 07:26 AM
main menu - by zoasterboy - 10-26-2005, 05:13 AM
joining - by phycowelder - 10-26-2005, 05:25 AM
^^ - by zoasterboy - 10-26-2005, 05:27 AM
Anyone interested in making a text adventure as a group? - by Anonymous - 10-26-2005, 05:34 AM
Re: ^^ - by Liquid Snake - 10-26-2005, 06:18 AM
cool! - by phycowelder - 10-26-2005, 06:56 AM
Anyone interested in making a text adventure as a group? - by Oz - 10-29-2005, 03:54 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)