Poke...

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Skipsy.

Hi,

I don't understand why the following code does not work :

BUFFER = AllocateMemory(1, 1024, 0) ; réserve 1 Ko
OpenConsole()

PokeW (BUFFER, 123)
PrintN (Str(*BUFFER) )

CloseConsole()
End

My ubderstanding is that poke is supposed to set '123' value in
memory address BUFFER (?)

Printn replies '0'

:-((
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

123, little endian, = $00,$7B, there's your answer!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by DemonHell.

Try this..

BUFFER = AllocateMemory(1, 1024, 0) ; réserve 1 Ko
OpenConsole()

PokeW (BUFFER, 123)
PrintN (Str(PeekW(BUFFER)))

CloseConsole()
End

Since BUFFER already holds the address of the alloc`d memory, you don`t need to use a "pointer to a pointer" to it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Skipsy.

Oh yes I know it works with peek but the goal is to send the whole
BUFFER with a SendNetworkData.

I have also tried different ways like
*BUFFER = 123
*(BUFFER+2) = 456 <-- does not compile

To summarize I just want to fill a fu#@& memory buffer...


"The game of life is hard to play..." :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by Skipsy

I have also tried different ways like
*BUFFER = 123
*(BUFFER+2) = 456 <-- does not compile
You have not understood how pointers work in PureBasic, it is not the same as in C.

Your first line "*BUFFER=123" sets the value of the pointer, not the memory it is pointing at. Therefore you need to use Poke or point to a structure to set the contents of the memory.

Your second line means nothing in PureBasic (as you can guess since it does not compile :).


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.51, Ed3.53)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by horst.

> PokeW (BUFFER, 123)
> PrintN (Str(*BUFFER) )

Skipsy:

first: Buffer and *Buffer are not the same variables.
second: the asterisk (*) is not a function or something like this;
it is just part of the name, and it is supposed to remind you
that you use the variable as a pointer. But you don't have to use
the asterisk. Buffer pointers work well without.

(Note that structures are a different issue, but here we talk about
plain buffer pointers.)

This means: your pointer variable name should be either
Buffer or *Buffer, but don't mix.


Horst
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Skipsy.

Wow....
It is (a bit) more clear now.
Still working on this...

Thks a lot.
ww
Post Reply