Dynamic memory allocation in C++ class
I am sure there is an alternative solution for this problem but I would really like to understand why my solution is not working
int n;
class Segtree
{
public:
int *s, size, h, *cl, *t; string a;
int open, close, total;
void init(string input,int siz)
{
size = siz;
n = size;
t = new int[size * 4];
cl = new int[size * 4];
s = new int[size * 4];
a = input;
build();
};
}
I am dynamically allocating memory to arrays inside a class but I am getting some errors with memory allocation you can find it in the results here.
After this I allocated the memory statically. Inside the class but everytime I allocate around 10^6 size in all 3 arrays I get segfault. Note that this segfault will not occur had the array been global. What would be a good way to allocate around 10^7 size to int arrays inside a class ?
上一篇: > C ++在没有给出类型的情况下,自动将void指针转换为C ++中的类型指针(#define)(C
下一篇: C ++类中的动态内存分配