Performance impact of realloc ()

前端 未结 4 2157
感情败类
感情败类 2021-02-18 15:41

I have a list of records, at the starting I dont know the number of records. I need to read them into array. so is it advisable to read all record one by one & doing reallo

4条回答
  •  甜味超标
    2021-02-18 16:27

    You should not realloc( ) one-by-one.

    The optimal strategy for this sort of thing depends on the specifics of what you're doing, but one common, simple, and nearly optimal approach is to increase your allocation size by a factor of two whenever you run out of room in your array.

提交回复
热议问题