Linking Linked List To Hard Disk

Posted on 2006-07-19
Last Modified: 2008-03-06
A simple linked list--

struct node{
int data;
node *next;

Generally when we create LL it gets created in RAM , what if I want to store it hard disk so that I can add / delete more nodes to it.

Question by:sinha_anshul26
  • 3
  • 3

Assisted Solution

sin_ earned 30 total points
ID: 17140890

Since it doesn't make any sense to store the pointers in the hard disk, you can store the data of the linked list into the hard disk by writing method like:

void makePersistent(NODE* root)
   // get each element and store the values in some file.

NODE* getPersistentList()
   //Read from the file.
   //create the link list and associated next ptrs.
   //return it.

The bottom line is, you store the data of the linked list, not the ptrs.

Author Comment

ID: 17143413
Hi Sin_
Just to confirm I got it right...
you  mean to say,(In other words) that there is no way that we can store data at a specific location of the Hard disk (using pointers)?

I read somewhere that OS does this to manage files using FAT file system

Accepted Solution

manish_regmi earned 20 total points
ID: 17143899
In Fat it is not pointers of address but the pointers of block.

for eg. if a file occupies four blocks in block 3 5 6 9,

fat 3 points to 5 points to 6 points to 9.
it means a 32 bit fat value has block number 5.

No there is no way you can store pointers in disk. In virtual memory system you get different address each time you run (esp in dynamically allocated memory).

Manish Regmi
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Expert Comment

ID: 17144178
That's right Anshu! Compiler generates the virtual memory addresses, which  are mapped to a physical page address by MMU while running the application. Therefore, everytime you run the application, you will find that your pointer is pointing to a different address.

Just imagine if you store this address; it may be a garbage next time. Persistence mechanism works by storing the content; you can reconstruct the data structure while reading it back.

Hope it helps.


Author Comment

ID: 17145400
>>Hope it helps
It Helped alot ...thank you both of you

Author Comment

ID: 17145443
Oh !! I choose the other way round sin_ 's  answer should be  Accepted and manish's assisted.
But any way thank you both for  helping


Expert Comment

ID: 17147130
Not a problem! I too didn't know anything about FAT ptrs :)


Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Handle Exceptions during instantiation 28 416
returning a dereferenced pts in C++ 10 151
Getting IP address 8 79
Move constructor only called if marked noexcept? 6 104
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question