新/调整大小 [英] new/ resize
问题描述
如何调整使用new分配的数组?
how do you resize an array allocated with new?
推荐答案
machine99写道:
machine99 wrote:
如何你调整分配了新的数组吗?
how do you resize an array allocated with new?
你不是。哟必须分配目标大小的新内存块
,然后在那里移动数据并取消分配原始数组。
任何你不使用的原因std :: vector,它处理
的大小调整?
You don''t. Yo have to allocate a new block of memory of the target size
and then move the data there and deallocate the original array.
Any reason why you don''t use std::vector, which handles resizing for
you?
> >你如何调整用new分配的数组?
> > how do you resize an array allocated with new?
你不是。哟必须分配一个目标大小的新内存块然后将数据移动到那里并释放原始数组。
任何理由你不使用std :: vector,它处理调整大小对于
你?
You don''t. Yo have to allocate a new block of memory of the target size
and then move the data there and deallocate the original array.
Any reason why you don''t use std::vector, which handles resizing for
you?
我使用std :: vector相当广泛,但总会有特殊的
情况:)
I do use std::vector quite extensively but there will always be special
cases :)
machine99写道:
machine99 wrote:
如何调整使用new分配的数组的大小?
how do you resize an array allocated with new?
你不是。哟必须分配一个目标大小的新内存块然后将数据移动到那里并释放原始数组。
任何理由你不使用std :: vector,它处理调整大小对于
你?
You don''t. Yo have to allocate a new block of memory of the target size
and then move the data there and deallocate the original array.
Any reason why you don''t use std::vector, which handles resizing for
you?
我使用std :: vector相当广泛,但总会有特殊的情况:)
I do use std::vector quite extensively but there will always be special
cases :)
实际上,首选或需要数组的情况
比std :: vector很少,不需要调整大小。
其中一些情况是代码/内存空间和执行时间。
但是,花费在开发上的时间(和开发成本)通常比任何过早的优化问题都重要。所有问题
当一个std :: vector应该被使用时涉及数组。
编程优先级(首先列出优先级最高):
1.质量&稳健性
2.开发时间(也与成本有关)。
3.用户互动或与环境互动。
4.代码空间和执行时间(即优化)。
如果程序无法正确转动电机,转动速度更快
或使用更少的代码来转动它是一个静音点。
-
托马斯马修斯
C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt
C ++常见问题: http://www.parashift。 com / c ++ - faq-lite
C常见问题: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c -c ++ faq:
http:// www。 RAOS .demon.uk / acllc-c ++ / faq.html
其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍
http://www.sgi.com/tech/stl - 标准模板库
Actually, the situations where an array is preferred or required
over a std::vector are few and don''t require resizing.
Some of these situations are code / memory space and execution time.
However, time spent developing (and development cost) usually
outweighs any premature optimization issues and all problems
involved with an array when a std::vector should have been used.
The programming priorities (listed with highest priority first):
1. Quality & robustness
2. Development time (also related to cost).
3. User interaction or interaction with the environment.
4. Code space and execution time (i.e. optimization).
If a program can''t correctly turn a motor, turning it faster
or using less code to turn it is a mute point.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
这篇关于新/调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!