More optimal array growth factor
http://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array
This commit is contained in:
parent
200abb1d75
commit
77bde2ea54
@ -155,10 +155,10 @@ static stringlist *insert_string(stringlist *list,char *string)
|
||||
break;
|
||||
if (i==list->size) {
|
||||
/* double the size of the list */
|
||||
newsize=list->size*2;
|
||||
newsize=list->size+list->size/2;
|
||||
if ((newstrings=realloc(list->strings,newsize*sizeof(char*)))==NULL)
|
||||
error(103); /* insufficient memory (fatal error) */
|
||||
memset(newstrings+list->size,0,list->size*sizeof(char*));
|
||||
memset(newstrings+list->size,0,list->size/2*sizeof(char*));
|
||||
list->strings=newstrings;
|
||||
list->size=newsize;
|
||||
} /* if */
|
||||
|
Loading…
x
Reference in New Issue
Block a user