Page 1 of 2

*MemoryBuffer

Posted: Thu Apr 24, 2025 6:31 pm
by rndrei
Tell me how to read the right byte from memory?

Code: Select all

*buffer = AllocateMemory(1000)
byte=*buffer(10)
byte2=*buffer[50]

Re: *MemoryBuffer

Posted: Thu Apr 24, 2025 6:40 pm
by Mijikai
Example:

Code: Select all

EnableExplicit

Structure BYTE_STRUCT
  byte.b[0]
EndStructure

Procedure.i main()
  Protected.BYTE_STRUCT *buffer
  *buffer = AllocateMemory(1000)
  If *buffer
    *buffer\byte[10] = $FF
    
    Debug *buffer\byte[10]
    
    ShowMemoryViewer(*buffer,1000)
    
    FreeMemory(*buffer)
  EndIf
  ProcedureReturn #Null
EndProcedure

End main()

Re: *MemoryBuffer

Posted: Thu Apr 24, 2025 6:50 pm
by infratec
Read the help about AllocateMemory() and look at the example.
There you can find PokeS()
Then press at the bottom of the help on Memory durectory and look at the available commands.

Hint: look deeper at the Peek commands

Re: *MemoryBuffer

Posted: Thu Apr 24, 2025 7:57 pm
by Quin
I've told you this before and I'll tell you again:
Please go read the PB docs in-depth. Many programming languages struggle with a lack of documentation, PureBasic is not one of them. The english isn't always spotless but it's super well-written and clear documentation.
What you want are the peek/poke commands under the Memory section of the help file :) PeekB to peek (view) a byte, PeekS to peek a string, etc.

Re: *MemoryBuffer

Posted: Thu Apr 24, 2025 9:49 pm
by Piero
Mijikai wrote: Thu Apr 24, 2025 6:40 pm Example:
Thanks!

Peek Poke Array on Mac:
https://www.purebasic.fr/english/viewto ... 49#p633249

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 6:12 am
by Demivec
rndrei wrote: Thu Apr 24, 2025 6:31 pm Tell me how to read the right byte from memory?

Code: Select all

*buffer = AllocateMemory(1000)
byte=*buffer(10)
byte2=*buffer[50]
The short answer is to do as Quin said and read the help manual instead of asking forum users to quote each page of it to you.

Here's a longer answer with no additional explanation:

Code: Select all

*buffer = AllocateMemory(1000)
byte = PeekB(*buffer + 10)
byte2 = PeekB(*buffer + 50)
LifeUniverseNEverything = (Bool(PeekB(*buffer + '*') > '*' ) +
                           Bool(PeekB(*buffer + '*') < '*' ) +
                           Bool(PeekB(*buffer + '*') = '*' )) * '*'

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 8:33 am
by Piero
Why are you gurus so angry @rndrei?
Sometimes (even if you know a bit of english!) it's not very easy to browse help………

PS: rndrei, did you see that you can also use the "PureBasic documentation in PDF format (full version)" to search stuff?

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 8:36 am
by jacdelad
Because he found AllocateMemory which includes an example which should lead you to the right way. :wink:

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 9:03 am
by Piero
jacdelad wrote: Fri Apr 25, 2025 8:36 am Because he found AllocateMemory which includes an example which should lead you to the right way. :wink:
Apropos: in my tests (but I tried on win 11 arm VM) the "array" method is always faster than peek/poke
https://www.purebasic.fr/english/viewto ... 49#p633249

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 9:08 am
by Demivec
Piero wrote: Fri Apr 25, 2025 8:33 am Why are you gurus so angry @rndrei?
Sometimes (even if you know a bit of english!) it's not very easy to browse help………
The help file is available in German and French as well. In addition, the online html version can be translated into other languages with the Chrome web browser's 'translate' option for web pages.

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 9:36 am
by Piero
Demivec wrote: Fri Apr 25, 2025 9:08 am'translate' option for web pages.
I guess you think so because your native language is english, so the automatic "translations" are generally decent; if that's the case, I can assure you that if you were, e.g., italian, you would "think VERY different" (especially if it involves pineapple pizzas)

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 9:50 am
by AZJIO

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 10:31 am
by Demivec
Piero wrote: Fri Apr 25, 2025 9:36 am
Demivec wrote: Fri Apr 25, 2025 9:08 am'translate' option for web pages.
I guess you think so because your native language is english, so the automatic "translations" are generally decent; if that's the case, I can assure you that if you were, e.g., italian, you would "think VERY different" (especially if it involves pineapple pizzas)
Languages and writing styles come in many flavors and are used in different and sometimes dicey levels of fluency. I mention automatic translations only as an additional option to having no translation. When I started with PureBasic the English version of the help file had many issues due to it being written by non native speakers. I survived and it has improved over the years. In addition to English I also communicate in German, French, and American Sign Language and have been a student of other languages including Spanish, Russian, Mandarin, and Japanese and would study many more if not for the lack of time. Some things do not translate well between different languages but a rough translation is often better than no translation.
Speaking of pineapple pizzas, I ate pineapple pizza con gusto for dinner. They're one of my favorites, among many others of course. :)

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 10:36 am
by Mijikai
Playing around:

Code: Select all

EnableExplicit

Macro CharBuffer(_buffer_);<- defines cmem!
  !char* cmem = (char*)p_#_buffer_;
EndMacro

Macro CharSet(_index_,_value_)
  !cmem[_index_] =  _value_;
EndMacro

Macro CharGet(_index_,_byte_)
  !v_#_byte_ = cmem[_index_];
EndMacro

Procedure.i main()
  Protected *buffer
  Protected.b byte
  *buffer = AllocateMemory(1000)
  If *buffer
    CharBuffer(buffer)
    CharSet(10,255)
    CharGet(10,byte)
    Debug byte
    ShowMemoryViewer(*buffer,1000)
    FreeMemory(*buffer)
  EndIf
  ProcedureReturn #Null
EndProcedure

End main()

Re: *MemoryBuffer

Posted: Fri Apr 25, 2025 11:16 am
by rndrei
Thanks for the different options, but I have never found documentation about reading the right byte from the buffer!
And I drank cappuccino!