Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 579423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:21:56+00:00 2026-05-13T14:21:56+00:00

I am working on a c parser and wondering how expert manage large amount

  • 0

I am working on a c parser and wondering how expert manage large amount of text / string (> 100mb) to store in memory?
the content is expected to be accessible all the time in fast pace.
bg: redhat / gcc / libc

a single char array would be out of boundary causing segmentation fault…
any idea or experience is welcomed to share / discuss…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:21:56+00:00Added an answer on May 13, 2026 at 2:21 pm

    mmap is the best way to deal with a large amount of data that is stored in a file, if you want random access to that data.

    mmap tells the virtual memory system to map a contiguous portion of address space to contain the data found in the file. The virtual memory system will allocate a range of address space, backed by that file. When you access any location in that address space, it will allocate a page of physical memory, read that section of the file in from the disk, and point that portion of your virtual address space to the physical memory that it used to read the file. When it needs to make more room in physical memory, it will write out any changes to disk (if applicable), and remove the mapping of that section of virtual address space.

    You would use it like so:

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/mman.h> /* the header where mmap is defined */
    #include <fcntl.h>
    
    int file;
    char *contents;
    struct stat statbuf;
    off_t len;
    
    file = open("path/to/file", O_RDONLY);
    if (file < 0)
      exit(1); /* or otherwise handle the error */
    
    if (fstat(file, &statbuf) < 0)
      exit(1);
    
    len = statbuf.st_size;
    
    contents = mmap(0, len, PROT_READ, MAP_SHARED, file, 0);
    if (contents == MAP_FAILED)
      exit(1);
    
    // Now you can use contents as a pointer to the contents of the file
    
    // When you're done, unmap and close the file.
    
    munmap(contents, len);
    close(file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a parser in php which is designed to extract MySQL records
I'm currently working on a parser for our internal log files (generated by log4php,
I'm currently working on a Mips Code Generator for my Pascal Parser (Written in
I have started working on a simple XML pull-parser, and as I've just defuzzed
I'm working on a Boost Spirit 2.0 based parser for a small subset of
I'm working with Quickbook's IIF file format and I need to write a parser
I'm working on implementing a reasonably simple XML serializer/deserializer (log file parser) application in
I am wondering if the following code is an old approach for working with
Hey I am working in python with datetime and I am wondering what the
Python 2.6 Using Python string.replace() seems not working for UTF-16-LE file. I think of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.