Re: memory related concerns



On 22 Jun 2006 00:54:10 -0700, 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.


Yes, assuming that your code compiles.

Return the header of the node and add an argument that specifies
whether you ran out of memory. It might look something like this:

struct list* my_function(int *out_of_memory_ptr)
{
/* implementation that sets *out_of_memory_ptr
and returns the header of the node */
}

--
jay
.



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)