Re: memory related concerns



sam_cit@xxxxxxxxxxx wrote:
Hi,

Everybody, i have a situation where i receive data in a buffer and i
read the buffer and store it in a linked list, one the problem is i can
receive any number of data... so i might run out of the memory, and the
utiltimate aim is to return the header of the linked list to the caller
of the function, so that they can process the list and do the concerned
thing.

ht list is like this

struct list
{
int date;
struct *list
};

so having seen this limitation, is there any way of work around,
where i still can return the header of the node to the caller and don't
run out of memory simultaneously.

Well, you could do lazy evaluation of the list. Read what you need
into the current node of the list. When the caller wants to process the
next node - call a function rather than just dereference node->next)
which read/generate and fills in the next link in the list and disposes the current node (incorporate instructions in the node so it knows
where to start reading from when you're processing the next node.)

Eventually this might just be a seemingly awkward way of streaming
chunks of data though :-)

.



Relevant Pages

  • Re: Problem in printing string, created in another function.
    ... This makes me feel that since I assign retval memory using automatic ... the caller will need to free the memory after it's ... The caller MUST completely finish using the buffer you formatted the ... string into before the next time the formatting routine is called, ...
    (comp.lang.c)
  • Re: style question,itoa
    ... sensible to have the caller pass in a buffer. ... technically useless malloc and free calls, ... priori when memory allocations would fail. ...
    (comp.unix.programmer)
  • Re: Why "segmentation fault"?
    ... As you know if you do it like this then the caller has to release ... it because all you have to do as the caller is free the memory ... a static array of chars and return a pointer to that. ... pointer as well as the length of the buffer to the function - ...
    (comp.os.linux.development.system)
  • Re: style question,itoa
    ... sensible to have the caller pass in a buffer. ... Dont intend to change that. ... Since the program i´ll use it cant eat up memory at an alarming rate i prefer manual intervention. ...
    (comp.unix.programmer)
  • Re: Detecting freed memory
    ... can easily see the parent article, or even the subject header. ... The parent article asked about how to detect, after a call to free, ... > buffer that can be checked. ... It would also have to initialize newly malloced memory with some ...
    (comp.lang.c)