shared memory and multidimensional arrays...

Discussion in 'C Programming' started by oopsatwork, Feb 19, 2008.

  1. oopsatwork

    oopsatwork Guest

    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 multidimensional
    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
    multidimensional arrays. I could always "simulate" a multidimensional
    array in a single dim. array, but that seems less than ideal. Any
    thoughts?

    Thanks,
    -mike
    oopsatwork, Feb 19, 2008
    #1
    1. Advertising

  2. oopsatwork

    oopsatwork Guest

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

    my bad... ;)

    -mike
    oopsatwork, Feb 19, 2008
    #2
    1. Advertising

  3. oopsatwork

    ppi Guest


    > point on different processes. So, my question is, whether or not
    > there is a "standard", or at least common, way of doing shared
    > multidimensional arrays. I could always "simulate" a multidimensional
    > 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.programmer.

    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.programmer.

    Cheers,
    Paulo
    ppi, Feb 19, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. d[ - - ]b

    Multidimensional arrays? anything else?

    d[ - - ]b, May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,665
    AlexS
    May 18, 2004
  2. Charles Banas

    multidimensional arrays and cute tricks

    Charles Banas, Jan 21, 2004, in forum: C Programming
    Replies:
    9
    Views:
    372
    Dave Thompson
    Feb 2, 2004
  3. Replies:
    7
    Views:
    566
    Barry Schwarz
    Jun 1, 2005
  4. Philipp
    Replies:
    21
    Views:
    1,111
    Philipp
    Jan 20, 2009
  5. Francesco
    Replies:
    2
    Views:
    1,089
    Francesco
    Nov 6, 2009
Loading...

Share This Page