Random PEEK()s ?

General FreeBASIC programming questions.
cbruce
Posts: 136
Joined: Sep 12, 2007 19:13
Location: Dallas, Texas

Random PEEK()s ?

Postby cbruce » Apr 10, 2018 0:09

Brain... hurt....

Just playing around and thought I would take a look at what is in my user memory space... but simple PEEK abends (abnormal end... dies a horrible death... quits running and Windows gives an error message... makes my brain hurt).

It is so simple, but can't remember what I am doing at all...

Code: Select all

dim ipeekptr as integer ptr
'
print "Peeks:"
for i = 1 to 50
    *ipeekptr = culng(rnd*100000ul)
    print tab(9); *ipeekptr; tab(35); peek(integer, ipeekptr)
next

Hmmm... Can I PEEK anywhere in my user space... or only in memory that I have allocated implicitly or explicitly?
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: Random PEEK()s ?

Postby D.J.Peters » Apr 10, 2018 0:34

There isn't a default user space only the space you are allocated can be read or written.

var user_memory = allocate(1024*1024*100) ' 100 MB

Joshy
paul doe
Posts: 1347
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Random PEEK()s ?

Postby paul doe » Apr 10, 2018 0:43

cbruce wrote:Brain... hurt....

Just playing around and thought I would take a look at what is in my user memory space... but simple PEEK abends (abnormal end... dies a horrible death... quits running and Windows gives an error message... makes my brain hurt).

It is so simple, but can't remember what I am doing at all...
...
Hmmm... Can I PEEK anywhere in my user space... or only in memory that I have allocated implicitly or explicitly?

You can PEEK anywhere, but you're actually writing to an unitialized pointer:

Code: Select all

dim ipeekptr as integer ptr = new integer '' <- allocate memory for an integer...
'
print "Peeks:"
for i as integer = 1 to 50
    *ipeekptr = culng(rnd*100000ul) '' <- ... so this line doesn't crash your code
    print tab(9); *ipeekptr; tab(35); peek(integer, ipeekptr)
next

sleep()

delete ipeekptr '' don't forget to release all memory explicitly allocated

You also forgot to declare the iterator in the for-next loop...

Return to “General”

Who is online

Users browsing this forum: Gunslinger and 12 guests