Originally Posted by
wkohlani
And in each call the following line is executed:
Code:
struct dependency *temp, *prev;
So, you're suggesting that I should put that line in global scope so that I only create those dummy variables once?
No, that's not at all what I'm saying.
Code:
double is_dependent(unsigned long long which_inst, enum stall_reason *where)
{
struct dependency *temp, *prev;
double ret_val = 0;
// Scan the chain for the dependent line
for(prev=NULL, temp=dc_head; temp && temp->which_inst != which_inst; prev=temp, temp=temp->next);
// Found. Unlink node and return when_satisfied
if(temp)
{
if(prev)
{
prev->next = temp->next;
}
else
{
dc_head = temp->next;
}
ret_val = temp->when_satisfied;
*where = temp->reason;
temp->next = freelist;
freelist = temp;
}
return ret_val;
}
More along the lines of that. Rather than actually call free a million times, just stuff it on another list. Then if you need to allocate one...
Code:
struct dependency *newdependency( void )
{
struct dependency *d = freelist;
if( d )
{
freelist = freelist->next;
}
else
{
d = malloc( sizeof *d );
}
return d;
}
It may not help you out, but I'm not sure that calling free over and over is really helping you speed things up. 'freelist' would be a global pointer to a structure.
Quzah.