Segementation Problem while accessing contents from Memory Mapped File

Discussion in 'C Programming' started by nkrisraj@gmail.com, Jan 10, 2006.

  1. Guest

    Hi,

    I have a following structure:
    typedef struct
    {
    RateData rdr;
    int RateID;
    char RateBalance;
    } RateInfo;


    typedef struct
    {
    DayRates *dr;
    WeekRates *wr;
    } TimeOfDayRates;

    First I will create the memoefy for the DayRates, WeekRates structures
    inside the RateInfo structure variable. After that Iam going to copy
    the contents into DayRates, WeekRatesstructures. Once the all the
    structure members inside RateInfo structure variable are initialized, I
    will add that node to a AVL tree. This way, Iam going to create an AVL
    tree by adding RateInfo nodes to it. Once the total tree is contructed,
    I will store this tree as file (rateinfo.map) on the disk.

    In my next programming component, Iam going to load this file
    (rateinfo.map) into memory using mmap() function call. Once I load the
    file into memory using mmap(), Iam able to access the RateID and
    RateBalance members of the RateInfo. But, Iam not able to access the
    DayRates, and WeekRates structure contents. When I try to access the
    members of DayRates , and WeekRates structures, my program is showing
    segmentation fault and Iam getting the core dump.

    Even though I allocated memory for DayRates , and WeekRates structures
    inside RateInfo node while creating the tree, why Iam not able to
    access contents of DayRates , and WeekRates structures when I mmap()
    file into memory?

    Any pointers would be a great help.

    Thanks,
    -Nikhil
     
    , Jan 10, 2006
    #1
    1. Advertising

  2. Guest

    Please find the correct structure declarations:
    typedef struct
    {
    RateData rdr;
    int RateID;
    char RateBalance;

    } RateInfo;

    typedef struct
    {
    DayRates *dr;
    WeekRates *wr;

    } RateData;
     
    , Jan 10, 2006
    #2
    1. Advertising

  3. Re: Segementation Problem while accessing contents from MemoryMapped File

    writes:
    [snip]
    > In my next programming component, Iam going to load this file
    > (rateinfo.map) into memory using mmap() function call. Once I load the
    > file into memory using mmap(), Iam able to access the RateID and
    > RateBalance members of the RateInfo. But, Iam not able to access the
    > DayRates, and WeekRates structure contents. When I try to access the
    > members of DayRates , and WeekRates structures, my program is showing
    > segmentation fault and Iam getting the core dump.
    >
    > Even though I allocated memory for DayRates , and WeekRates structures
    > inside RateInfo node while creating the tree, why Iam not able to
    > access contents of DayRates , and WeekRates structures when I mmap()
    > file into memory?


    There is no mmap() function in standard C (it's defined by POSIX, a
    separate standard). You'll need to ask in a newsgroup for your
    system, perhaps comp.unix.programmer.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jan 10, 2006
    #3
  4. Re: Segementation Problem while accessing contents from MemoryMapped File

    In article <>,
    Keith Thompson <> wrote:

    >There is no mmap() function in standard C (it's defined by POSIX, a
    >separate standard).


    True, but his real problem was in trying to use a pointer created
    in one execution in a different execution. He could have just
    read() the same data into a block of memory and tried to use it,
    to the same failed effect. mmap() was a red herring in this problem.
    --
    I was very young in those days, but I was also rather dim.
    -- Christopher Priest
     
    Walter Roberson, Jan 10, 2006
    #4
    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. Replies:
    0
    Views:
    283
  2. Replies:
    8
    Views:
    418
    Keith Thompson
    Jan 10, 2006
  3. didier2309

    segementation fault

    didier2309, May 9, 2006, in forum: C Programming
    Replies:
    23
    Views:
    713
    Keith Thompson
    May 11, 2006
  4. priyanka

    segementation fault

    priyanka, Jul 18, 2006, in forum: C Programming
    Replies:
    7
    Views:
    303
    Keith Thompson
    Jul 19, 2006
  5. Chris Brooks

    memory mapped tar file contents

    Chris Brooks, Nov 13, 2008, in forum: Python
    Replies:
    1
    Views:
    379
    Aaron Brady
    Nov 13, 2008
Loading...

Share This Page