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

  • SEARCH
  • Home
  • 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 3235638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:31:47+00:00 2026-05-17T17:31:47+00:00

I am trying to find how to store and process (search, add, remove) an

  • 0

I am trying to find how to store and process (search, add, remove) an array of linked lists on disk. For example in memory, it would like

struct list {
 int a;
 struct list *next;
}LIST

LIST *array[ARRAY_SIZE]

int main{
...
 LIST *foo = array[pointer];
 /* Search */
 while(foo!=NULL){
   ...
   foo=foo->next
 }
}
  1. I believe that by using fseek() I can point to a specific element/structure of the array in the file. But I cannot understand if all previous elements need to have been written or not.
  2. Can this be done with dynamic allocation on disk?
  3. How will I link on element to another one in the linked list?
    Any example would certainly help!
  • 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-17T17:31:47+00:00Added an answer on May 17, 2026 at 5:31 pm

    Okay, as Amardeep says, this sounds like the sort of thing that would best be done practically using some kind of database, like, or, Berkeley DB. But let’s answer the questions anyway.

    1. you can indeed use fseek (or its system call, lseek) to determine where something is on the disk and find it later. If you use some method of computing the offset, you’re implementing what we used to call a direct file; otherwise you might store an index, which leads you off toward the indexed sequential method.

    2. whether it can be done with dynamic allocation sort of depends on the file system. Many UNIX file systems support * sparse* allocation, which means that if you allocate block 365 it doesn’t have to allocate blocks 0 through 364. Some dont.

    3. Let’s say that you have a structure with a length k that looks more or less like this:

    (trick the parse)

    struct blk { 
        // some stuff declared here
        long next;  // the block number of the next item
    };
    

    You create the first item; set its block number to 0. Set next to some distinguished value, say -1.

    // Warning, this is off the cuff code, not compiled.
    struct blk * b = malloc(sizeof(struct blk));
    // also, you should really consider the case where malloc returns null.
    
    // do some stuff with it, including setting the block next to 1.
    lseek(file, 0, SEEK_SET);  // set the pointer at the front of the file
    write(file, sizeof(struct blk), b);  // write it.
    free(b);
    
    // make a new block item
    malloc(sizeof(struct blk));
    // Do some stuff with it, and set next to 2.
    lseek(file, 0, SEEK_CUR);  // leave the pointer where it was, end of item 0
    write(file, sizeof(struct blk), b);  // write it.
    free(b);
    

    You now have two items on disk. keep this up and you’ll eventually have a thousand items on disk. Now, to find item # 513, you just

    lseek(file, (sizeof(struct blk)*513), SEEK_SET);
    

    You need a buffer; since we freed the previous ones we’ll make another

    b = malloc(sizeof(struck blk);
    

    Read that many bytes

    read(file, sizeof(struct blk), b);
    

    And poof record 513 is in memory pointed to by b. Get the record following with

    lseek(file, (sizeof(struct blk)*b->next), SEEK_SET);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find out how much memory my own .Net server process is
still trying to find where i would use the yield keyword in a real
I'm in the process of trying to make a game-in-progress more modular. I'd like
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to find the sqlserver adapter for rails on windows. I have tried getting
Trying to find an XML file I can use in lieu of a look-up
Im trying to find out a good JavaScript library that can create a nice
Been trying to find a working implementation of a WPF listview (or listbox) where
Im trying to find a best practice to load usercontrols using Ajax. My first
I'm trying to find the correct names for these 2 types of coding expressions

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.