Re: Dynamic memory allocation:Reading a file into buffers using a single linked list!



> 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

.



Relevant Pages

  • Re: Fast way to allocate buffer for producer/consumer scenario
    ... > queue and triggers another thread to handle the received data. ... > ownership of the buffer and the network service thread allocates a new ... I guess that the probably fastest way would be a dedicated memory ...
    (microsoft.public.vc.language)
  • Re: allocating stl containers in memory buffer
    ... > memory buffer? ... > but won't integer variables (and possible others needed by queue object) ... > allocated using default allocator outside the buffer? ... allocator to your queue object. ...
    (comp.lang.cpp)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Discovering variable types...
    ... >memory it points to is on the heap. ... sequentially reading data, if one is randomly reading records, then a ... >project is what's prompting me to improve disk access. ... from a memory buffer I can do it in about a second. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Multicast Directshow Graph Bridging, COW Rustling, & the Use of Portable Holes in Cartoon Ph
    ... memory to share buffer pools across processes and works pretty well. ... You get two basic Direct Show filters, ... issue each GMF-source a virtual memory alias with COW ...
    (microsoft.public.win32.programmer.directx.video)

Loading