Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using DATA like arrays
#8
ooh, well... a pointer is just a type of data, like an integer(3 for instance), or a single (3.27838743 for intstance) or a string ("hello" for instance)

the difference is, all of these data types, the integer, the single, and the string, have different places in memory where theyre sitting. everything FB does has a place in memory where it sits untiil you need it.


now heres a little theory:

Here we have a program that has three variables; x, y, and px. x and y are integer variables. px is a pointer to the location of x.


Code:
dim as integer x, y
dim as integer ptr px

x = 100
y = 64

px = @x



now, when fb makes your program, its got to give all of those data places in memory. x needs a place, and y and also px need a place in memory. so:

x = Address 4 (length of an integer is 4 bytes)
y = Address 8 (length of an integer is 4 bytes)
px = Address 12 (length of a ptr is 4 bytes)



so, since x = 100, that means "100" is at memory location 4. y = 64 so "64" is at memory location 8.

now the new part. px is holding the address of x (@x) which is Address 4. px = 4, so if we remember from before...

"x = 100, 100 at address 4"
"y = 64, 64 at address 8"
"px = 4, 4 at address 12"


okay!

any more questions just ask. heres one before you do, to read whats at the address of a pointer, use "*"


Code:
dim as integer x, y
dim as integer ptr px

x = 100
y = 64
px = @x

? *px
*px = 300 '' changed what was really in x!

? x
sleep


p.s. all the code here is untested
Reply


Messages In This Thread
Using DATA like arrays - by axipher - 03-04-2006, 06:58 AM
Using DATA like arrays - by d.j.peters - 03-04-2006, 07:12 AM
Using DATA like arrays - by Dr_Davenstein - 03-04-2006, 11:37 PM
Using DATA like arrays - by wallace - 03-05-2006, 01:47 AM
Using DATA like arrays - by axipher - 03-05-2006, 09:56 PM
Using DATA like arrays - by wallace - 03-06-2006, 12:36 AM
Using DATA like arrays - by axipher - 03-06-2006, 12:42 AM
Using DATA like arrays - by Anonymous - 03-06-2006, 10:39 AM
Using DATA like arrays - by wallace - 03-06-2006, 08:20 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)