由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 不用STL, C++里怎么realloc?
相关主题
请教,call c++ shared lib in java via jni求教调试内存错误的经验
weird output
相关话题的讨论汇总
话题: realloc话题: stl话题: c++话题: so话题: array
进入Programming版参与讨论
1 (共1页)
s*****k
发帖数: 604
1
比如一个object array, 要再加长点,
C里面用realloc,但是realloc不调用构造函数
c*****t
发帖数: 1879
2
Can't use realloc, because if resizing isn't successful, the old
memory would be freed before you have any chances calling dtors.
So, you will just have to use malloc/new to create a new memory
space, and then call placement new with copy constructor on each
and individual array element.
You can read std::vector code yourself to see how that gets
implemented.

【在 s*****k 的大作中提到】
: 比如一个object array, 要再加长点,
: C里面用realloc,但是realloc不调用构造函数

a****l
发帖数: 8211
3
the idea of realloc is against the physical design of digital computers, so
it is something you should avoid using in the first place.

【在 s*****k 的大作中提到】
: 比如一个object array, 要再加长点,
: C里面用realloc,但是realloc不调用构造函数

s*****k
发帖数: 604
4
读了stl_alloc.h,读不懂啊

【在 c*****t 的大作中提到】
: Can't use realloc, because if resizing isn't successful, the old
: memory would be freed before you have any chances calling dtors.
: So, you will just have to use malloc/new to create a new memory
: space, and then call placement new with copy constructor on each
: and individual array element.
: You can read std::vector code yourself to see how that gets
: implemented.

1 (共1页)
进入Programming版参与讨论
相关主题
请教,call c++ shared lib in java via jni求教调试内存错误的经验
weird output
相关话题的讨论汇总
话题: realloc话题: stl话题: c++话题: so话题: array