Я запускаю эту программу на C++, которая постоянно дает мне sysmalloc assertion
ошибка. Я использую g ++ - 4.8.sysmalloc assertion не удалось использовать вектор
# include <iostream>
# include <complex>
# include <vector>
# include <stdlib.h>
# include <time.h>
# include <climits>
# include <cstdio>
#define getRand(x,y) (rand()%((y)-(x)+1)+(x))
using namespace std;
typedef complex<double> Complex;
typedef struct compositeSignal{
int *frequency;
int *amplitude;
int num;
compositeSignal(int n)
{
frequency = new int(n);
amplitude = new int(n);
num = n;
for(int i=0;i<num;i++)
{
amplitude[i] = getRand(1,100);
cout<<amplitude[i]<<" ";
frequency[i] = getRand(100,600);
cout<<frequency[i]<<endl;
}
}
double getVal(double t)
{
double val = 0;
for(int i = 0;i<num;i++)
val += amplitude[i]*sin(2*3.142*frequency[i]*t);
return val;
}
}compositeSignal;
int main()
{
srand(time(NULL));
int numOfSig = 5;
compositeSignal sig1(numOfSig);// sig2(numOfSig); //define and initialize 2 composite signals
vector<int> result(10);
}
ОШИБКА:
a.out: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinp
tr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offseto
f (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned l
ong) (old_size) >= (unsigned long)((((__builtin_offsetof (struct
malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((
2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((uns
igned long)old_end & pagemask) == 0)' failed.
Aborted
Ошибка, когда в последней строке я выделяю вектор result
. Как избежать этой ошибки?
То, что я не понимаю, - это то, почему вы не использовали вектор в коде составного кода вместо использования «нового» (который использовался в любом случае, как указано в ответе). Кроме того, «struct typedef» не требуется в определении структуры C++. – PaulMcKenzie
См. Мой ответ [здесь] (https://stackoverflow.com/questions/31936229/c-sysmalloc-assertion-failure/46511080#46511080), то же самое случилось со мной. – forumulator