Hi guys,
I'm a beginner in C and I need to handle memory. I have lot of arrays, most of all of pretty big size, and I'd like to know if I'm using fine the memory management.
Code:
complex *originalSignal = malloc(OVERLENGTH*sizeof(complex));
complex *noisevector = malloc(OVERLENGTH * sizeof (complex));
complex *receivedSignal = malloc(OVERLENGTH * sizeof (complex));
complex *copiaOriginale = malloc(OVERLENGTH * sizeof (complex));
complex *crossCorrVect;
I generate 4 arrays of size of OVERLENGTH complex items.
The last one is a simple pointer that will become an array. A function gets this pointer as parameter and builds an array; the size of this array is determined by the function, so I don't know if I should malloc here in the main, or just declarate the variable even in the function without using malloc.
By the way, my main function goes on: when I need to free space with these arrays I just need to do:
Code:
free(copiaOriginale);
free(originalSignal);
...
Is it wrong to do the same with the array crossCorrVect, which I didn't allocate with malloc?
Code:
free(crossCorrVect);
Is there a way to check if i really deleted the arrays?
I tried to make a check like:
Code:
if(originalSignal[randomindex]==NULL)
printf("ok");
but I get == as invalid operator.