On Thu, Aug 06, 1998 at 07:36:29PM +0000, James wrote:
> i'm writing a program that uses a linked list (actually it uses lots of
> linked lists, all linked together...) and it's all working nicely, i use
> malloc() to allocate the ram when needed and would like to know if malloc()
> uses Linux swap when it runs out of 'real' ram
Effectively yes. Behind the sceens the OS tries to get you some real memory by
swapping something (maybe another bit of your memory) out to disk, but at the
level of abstraction of malloc, its all just grabbable virtual memory.
> 
> and i make a list with it, how do i free all the ram that the list uses? this
> is the part of lists i could never work out.
> 
> node_t *mylist, *temp;
> 
> build_a_list (mylist);
> while (mylist) {
>       temp = mylist;
>       free (mylist);
>       mylist = temp->next;
> }
Not quite, when you free mylist you're freeing temp too. Try,
 while (mylist) {
        temp = mylist;
        mylist = temp->next;
        free (temp);
 }
Hope that helps,
Colin

Reply via email to