C (250/304)

From:Jack York
Date:29 Aug 2000 at 14:17:48
Subject:Re: Freeing list with Classact

Hello Rod

On 28-Aug-00, Rod Schnell wrote:

>>> to detach
>>> the list, walk it, free each node and then reattach the list after all
> the
>>> nodes have been freed. This way there's only one refresh.
>>
>> This is how I do it too. I'm not getting any hits, just slow memory
>> freeing.
>
> Are you absolutely positive the list is not attached to a listbrowser?
> That's about the only thing I can I think of that could cause such a large
> difference in free two identical lists. I'll try a two list test at home
> tonight and see what happens.

Yes, absolutely sure. But your question did bring up another clue.
This is basically what I do when I generate the two lists:

struct mystruct *temp; //dynamically allocated - not shown

for ( i = 0; i < 5000; i++)
{
strcpy(temp->name, "some name"); //also fill in rest of struct

AddToList( list_1, temp);
AddToList( list_2, temp);
}
And when I free these two lists, the first takes about 20 seconds while
the second takes about 3. But if I only generate the first list with the
above method and then generate the second list from it, like this:

for ( temp = list->lh_Head; temp; temp = temp->nn_Node.ln_Succ)
{
strcpy(temp->name, "some name"); //also fill in rest of struct

AddToList( list_2, temp);
}

both lists free in about 3 seconds. I'm not doing anything special in the
AddToList function. Just allocate a node, copy the contents of temp
to it and add it to the list. I appreciate your assistance with this. If
it would make it easier for you I can send you the code for this example
listbrowser. It's pretty short.

Jack