Re: how to write a structure in a shared mem segment.




nass wrote:
hi all,
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...

and i don't think i can use sprintf because it needs you to define the
type of variable you are giving as an argument to it (%d for decimal,
%f for float, %p for pointer, %s for string etc..) and i do not know
how to 'define' the structure that i want to save... or am i wrong in
thinking that and there is a type i can use to store my structure?

i have already posted a similar msg in c++ groups, but they suggested
that this is a more appropriate group to write to.
thankyou for your help
nass

I've a question if you are using mmap then when you write it the
memory, will it not be written to the file?

-kondal

.



Relevant Pages

  • Re: how to write a structure in a shared mem segment.
    ... nass wrote: ... 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.. ... and then use mmap to get a void* file_memory pointer. ...
    (comp.os.linux.development.apps)
  • how to write a structure in a shared mem segment.
    ... 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.. ... and then use mmap to get a void* file_memory pointer. ...
    (comp.os.linux.development.apps)