Re: Dynamic memory allocation:Reading a file into buffers using a single linked list!
- From: "Hemanth" <hemanth.singamsetty@xxxxxxxxx>
- Date: 29 Sep 2005 11:40:09 -0700
> I want to read a file using fread() and then put it in to memory. I
> want to use a (singel) linked list to continousely (dynamically) free
> up more memory when needed and put the buffers with the data of the
> file on a sort of stack.
> The problem is that i have no idea how to do this.
>
......I believe, a queue implementation suits well for this case (for
eg. if you want to process file with size larger than main memory, you
have to read it in chunks of constant size and store it in a buffer).
Here the queue can act as a buffer.
Queue can be implemented using a single linked list (maintain both
first and last pointers, always add nodes at Last and remove First Node
--FIFO)
Eg.
struct node
{
char* buffer; //Replace char* with whatever you want
struct node* first;
struct node* last;
};
- Construct a queue with "n" nodes;
- Remove first node (process data and clear buffer)
- Read another chunk of data from file and add it as a last node in
queue.
You can keep loop the last two steps.
> My question is: Does anyone of you have an example of how to read in an
> file and put it into memory using a singel linked list or maybe know a
> site where I can find an example?
>
.......search for a Queue implementation on google.
- Hemanth
.
- References:
- Prev by Date: Re: trying to compile with clock_settime(...)
- Next by Date: Re: A[x][y][z]
- Previous by thread: Re: Dynamic memory allocation:Reading a file into buffers using a single linked list!
- Next by thread: trying to compile with clock_settime(...)
- Index(es):
Relevant Pages
|
Loading