0 c++
可以使用旧块获取并初始化一个新的,可能更大的块,然后释放旧块.
purpose of that code ; reallocating the old memory area with new size
typeName is Object
Object *oldArray = objects ; // objects is pointer to old data block
objects = new Object[ newCapacity ] ;
for ( int k = 0; k < theSize ; k++ )
objects [k] = oldArray [k] ;
... // some other thing
delete [] oldArray ;
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以有效地完成这项工作吗?
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |