<分区>
我正在使用 C++ 中的数组列表,每个数组都在一个对象中,并且想拆分其中的一些。 这些是动态分配的。
我想在恒定时间内进行拆分,因为理论上是可行的: 来自
[ pointer, size1 ]
到
[ pointer, size2 ]; [ other array ]; [ pointer + size2, size1-size2 ]
(+ other data each time)
我尝试使用 malloc
并简单地创建一个随着大小递增的新指针。
不出所料,由于自动释放内存,我遇到了错误。
我尝试了从第二个地址开始的 realloc
,但是就像这个网站上的“malloc
和 calloc
有什么区别”已经告诉我这是不可能的。
有没有办法避免重新复制第二部分并正确定义指针? 在我知道我可以有固定时间的地方有一个线性成本是令人沮丧的。
class TableA
{
public:
(constructor)
void divide(int size); // the one i am trying to implement
(other, geteur, seteur)
private
Evenement* _el;
vector<bool>** _old;//said arrays
int _size;
}
没什么特别复杂的