Page 1 of 1

Posted: Fri Feb 14, 2003 12:18 pm
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'

:-((

Posted: Fri Feb 14, 2003 12:36 pm
by BackupUser
Restored from previous forum. Originally posted by dmoc.

123, little endian, = $00,$7B, there's your answer!

Posted: Fri Feb 14, 2003 12:40 pm
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.

Posted: Fri Feb 14, 2003 1:11 pm
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:

Posted: Fri Feb 14, 2003 4:51 pm
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)

Posted: Fri Feb 14, 2003 5:38 pm
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

Posted: Sat Feb 15, 2003 9:47 am
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