pointer question

Just starting out? Need help? Post your questions and find answers here.
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 waffle.

not sure if this is a "beginner question"....

the recieve network data function places the data into a buffer
thusly... *Buffer

i can recieve a pointer to a structure by *Mystruct
how do i quickly copy the data from Buffer to Mystruct ?
copy memory only works with memory addresses (or was that ID)
is this where i would use inline assembly with a code like
mov @buffer,size to @Mystruct ?

it seems like another simple question from me,
but i don't have a boom on that.... yet.
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 Pupil.
Originally posted by waffle

not sure if this is a "beginner question"....

the recieve network data function places the data into a buffer
thusly... *Buffer

i can recieve a pointer to a structure by *Mystruct
how do i quickly copy the data from Buffer to Mystruct ?
copy memory only works with memory addresses (or was that ID)
is this where i would use inline assembly with a code like
mov @buffer,size to @Mystruct ?

it seems like another simple question from me,
but i don't have a boom on that.... yet.
You could use the copymemory() command, the manual states that the 'SourceMemoryID' and 'DestinationMemoryID' is the memory address that you want to copy from and copy to. This would do i guess:

Code: Select all

CopyMemory(*buffer, *Mystruct.YourStructType, SizeOf(YourStructType))
Just some caution, the struct pointer MUST point to a variable(of same structure) or memory that you have previously allocated or your program would crash for sure. I.e. something like this:

Code: Select all

var.YourStructType
*MyStruct.YourStrucType = @var
; or memory
*MyStruct.YourStructType = AllocateMemory(0, SizeOf(YourStructType), 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 waffle.

thanks.
once again i am overwelmed by such simplicity.
but as someone once said
"simple code is effecient code" :)
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 waffle.

actually, i found the root cause of my confusion....

*F reserves a variable for the use as an actual address (pointer)
@F returns the actual address that must be stored into a pointer....

*F+25 shift the address of *F by 25 bytes

this stuff is coming back to me :)
Post Reply