shared memory and multidimensional arrays...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oopsatwork

    shared memory and multidimensional arrays...

    Ok...so, I have been outside of the C world for a _very_ long
    time...but not so long as to remember how to do multidimensiona l
    arrays. So, let me state that I know how to malloc pointers to
    pointers and then malloc my data space. This question is NOT about
    that.

    I need to keep a dynamically sized (a result of command line options)
    matrix in a shared memory segment created via shmget and attached via
    shmat. My first instinct was to do what I would do if I were using
    malloc. However, the docs for shm.h tell me that it is not safe to
    share my pointers, as the shared memory may be attached at a different
    point on different processes. So, my question is, whether or not
    there is a "standard", or at least common, way of doing shared
    multidimensiona l arrays. I could always "simulate" a multidimensiona l
    array in a single dim. array, but that seems less than ideal. Any
    thoughts?

    Thanks,
    -mike
  • oopsatwork

    #2
    Re: shared memory and multidimensiona l arrays...

    That should have said..."not so long as to _fail_ to remember how to
    do multidimensiona l arrays."

    my bad... ;)

    -mike

    Comment

    • ppi

      #3
      Re: shared memory and multidimensiona l arrays...

      point on different processes. So, my question is, whether or not
      there is a "standard", or at least common, way of doing shared
      multidimensiona l arrays. I could always "simulate" a multidimensiona l
      array in a single dim. array, but that seems less than ideal. Any
      thoughts?
      You do not have many options here. You'd have better luck in
      comp.unix.progr ammer.

      The shared memory segment is one big chunk of memory mapped to your
      current address space, it does not carry any more information than
      that. Your code will be the one responsible to make this big piece of
      memory meaningful.
      As you said, pointers cannot be shared (since they are tied to each
      process address space and hence likely to be different for every
      process) as such, each process that maps this shared memory segment
      will be responsible for indexing it for further processing.
      By sharing the number of lines and columns of the memory segment plus
      its data, each of your processes will be able to index it correctly.
      You should be able to navigate through this memory chunk pretty easily
      with the lines/columns you shared with it. The only trick is to
      actually make sure these infos (meta-datas) are stored with it (like a
      fixed-size header).

      If you have more questions about it, ask them on comp.unix.progr ammer.

      Cheers,
      Paulo

      Comment

      Working...