Re: how to write a structure in a shared mem segment.
- From: "Nils O. Selåsdal" <NOS@xxxxxxx>
- Date: Mon, 25 Sep 2006 12:18:21 +0200
nass wrote:
hi all,A void * can be converted to any pointer you want. It's up to
i am running slackware linux and need to use some function that will
will enable me to write and read a STRUCT from a shared mem segment..
i am using open() , to open a file (and get the file descriptor fd
returned), and then use mmap to get a void* file_memory pointer.
function fwrite() (from stdio.h) doesn't work cause it can write to a
file (ie needs a FILE* nor a void* and casting in this case makes the
executable crash), nor does write() (from unistd.h), ie the linux
standard write function, that needs as input the file decriptor (int)
fd instead of the (void*) file_memory pointer...
you to keep track of what you stuff where, and their types.
If you want to store an int at the start of your buffer/file:
void *memptr = ... ;
int *i = memptr;
*i = 42;
sprintf(memptr,"%d",42); will store the string "42" at that location.
For a struct you'd just do:
struct Foo *fptr = memptr;
.
- References:
- Prev by Date: how to write a structure in a shared mem segment.
- Next by Date: Re: one-to-one client server design
- Previous by thread: how to write a structure in a shared mem segment.
- Next by thread: Re: how to write a structure in a shared mem segment.
- Index(es):
Relevant Pages
|