Is there a way to make pointer variables in QBASIC? That would be handy for a GUI...
Also, can someone give me a quick overview of the pro's and con's of PEEK and POKE?
Gracias.
Pointers, PEEKing, and POKEing
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Re: Pointers, PEEKing, and POKEing
No, use integers or longs.Patz QuickBASIC Creations wrote:Is there a way to make pointer variables in QBASIC? That would be handy for a GUI...
Pros:Also, can someone give me a quick overview of the pro's and con's of PEEK and POKE?
-freedom
-speed
-power
Cons:
-can lead to bad crashes
-can corrupt your BIOS (if using pure DOS)
-some people find them ahrd to use
I'm sure someone will provide more pros and cons.
I have left this dump.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
I would have NEVER guessed to look in the online help. BRILLIANT!!!Z!re wrote:How useful. No, really, I'm not being sarcastic, I'm sure this is exactly the kind of reply Patz was looking for, keep up the amazing work!Skyler wrote:Cons:
I dont know how to use them.
Pros:
There is an entry in the help file.
Z!re, how exactly do they create crashes? Isn't there a way to allocate STACK space (I know the STACK and CLEAR commands) and get the memory addresses they use?
Also, how do they corrupt your BIOS? Don't want that to happen...
QB's peek and poke can not only access memory, but "hardware" aswell (Actually, memory linked to the hardware, but lets be simple)Patz QuickBASIC Creations wrote:I would have NEVER guessed to look in the online help. BRILLIANT!!!Z!re wrote:How useful. No, really, I'm not being sarcastic, I'm sure this is exactly the kind of reply Patz was looking for, keep up the amazing work!Skyler wrote:Cons:
I dont know how to use them.
Pros:
There is an entry in the help file.
Z!re, how exactly do they create crashes? Isn't there a way to allocate STACK space (I know the STACK and CLEAR commands) and get the memory addresses they use?
Also, how do they corrupt your BIOS? Don't want that to happen...
And the way you'd use them is to use a DIM and create an array, you'd then do something along the lines of:
Code: Select all
dim myPtr as long
dim myMemory(10000) as integer
myPtr = VARPTR(myMemory(0)
POKE myPtr+30000, 100 'because we dimed the array as integer, it actually holds 40'004 bytes, remember it start at 0
Print PEEK(myPtr+30000)
Now, lets take the above example and make it nasty:
Code: Select all
dim myPtr as long
dim myMemory(100) as integer '404 bytes, once again, remember it starts at 0 and integer = 4 bytes, 101*4 = 404
myPtr = VARPTR(myMemory(0)
POKE myPtr+3000, 100
Print PEEK(myPtr+3000)
In addition, POKEing to certain memory addresses could overwrite the BIOS settings.
To keep safe, you generally only PEEK/POKE memory that you created via DIM.
I have left this dump.