多少开销不realloc的电话介绍? [英] How much overhead do realloc calls introduce?

查看:143
本文介绍了多少开销不realloc的电话介绍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的realloc 循环的每个迭代的迭代更多的10000倍。

I am using realloc in every iteration of a for loop that iterates more that 10000 times.

这是一个好的做法呢?将的realloc 事业的一个错误,如果它被称为很多次?

Is this a good practice? Will realloc cause an error if it was called a lot of times?

推荐答案

它不会失败,除非你已经用完了内存(这与其他任何分配发生为好) - 但你的code通常如果你设法估计所需的存储前期运行更快。

It won't fail unless you've run out of memory (which would happen with any other allocator as well) - but your code will usually run much quicker if you manage to estimate the required storage upfront.

通常情况下,最好做一个额外的循环运行完全确定的存储要求。

Often it's better to do an extra loop run solely to determine the storage requirements.

我不会说的realloc 是一个没有去,但它要么不是好的做法。

I wouldn't say that realloc is a no-go, but it's not good practice either.

这篇关于多少开销不realloc的电话介绍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆