RE: peek and poke under Windows XP

new topic     » goto parent     » topic index » view thread      » older message » newer message

Martin -

Thanks.  I had tried that.  I was using the peek({a,n}) function because 
it is significantly faster than looping through p(a).  It's amazing how 
much trouble I get into trying to go faster!

Euman sent me another fix using a kernel32.dll function to find the 
length of the string from the address.  I suspect something like this or 
a c-function equivalent is needed to do this sort of thing using Windows 
XP and exw.exe.  The XP virtual machine gets upset when I try to read 
memory I have not allocated.

Thanks to both of you.

  George

Martin Stachon wrote:
> George Orr <georgeorr at donet.com> writes:
> > I am trying to create functions to rapidly put and get strings from 
> > memory using allocate_string() and peek.  The basic functions are
> > 
> > constant maxlength = 22    -- maximum length of word in dictionary
> > 
> > function put_word(sequence word)
> >   atom aword
> >   aword = allocate_string(word)
> >   return aword
> > end function
> > 
> > function get_word(atom a)
> >   sequence w
> >   integer i
> >   w = peek({a,maxlength})
> >   i = 1
> >   while w[i]>0 do i += 1 end while
> >   return w[1..i-1]
> > end function
> > 
> > The above functions work in Windows XP using ex.exe or exw.exe with 
> > trace turned on.  Using under exw.exe without trace gives system errors. 
> > 
> >  As you suggested, this seems to be an XP Virtual Machine issue.  The 
> > peek({a,maxlength}) accesses memory that has not been allocated.  Using 
> > ex.exe or exw.exe with trace on, this returns junk in the later bytes of 
> > 
> > the string, but the original string can be recovered by searching for 
> > the first 0 byte.  Apparently the XP virutal machine objects to 
> > accessing memory that has not been allocated.  When I modify the 
> > put_word function to pad the string to length maxlength, everything 
> > works in exw.exe.  
> > 
> > blankstr = repeat(0,maxlength)
> > function put_word(sequence word)
> >   atom aword
> >   sequence bword
> >   bword = blankstr
> >   for i = 1 to length(word) do
> >     bword[i] = word[i]
> >   end for
> >   aword = allocate_string(bword)
> >   return aword
> > end function
> > 
> > There may be other problems with my coding, but it looks like the XP 
> > Virtual Machine may just be too smart for me!
> 
> No more the DOS days when you could do everything with the machine... 
> smile
> 
> > Thanks for your help.  Please let me know if you see anything else that 
> > may be causing this.
> 
> The other way to fix is to replace get_word():
> 
> function get_word(atom a)
>     integer i,char
>     sequence s
>     i = 0
>     s = ""
>     while 1 do
>         char = peek(a+i)
>         if char = 0 then
>             -- end of string
>             exit
>         else
>             s &= char
>             i += 1
>         end if
>     end while    
>     return s
> end function
> 
> -- Martin
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu