B
Bart Vandewoestyne
I'm trying to allocate 3 vectors within a function. This is what
I do:
I declare the three vectors as pointers to doubles:
double *Hx;
double *Hy;
double *Ez;
I then have the function that allocates the memory for the
vectors:
void allocate_maxwell_fields_2d(int K, int Np,
double *Hx, double *Hy, double *Ez) {
Hx = (double*) calloc(K*Np, sizeof(double));
Hy = (double*) calloc(K*Np, sizeof(double));
Ez = (double*) calloc(K*Np, sizeof(double));
}
And I call the function as follows:
allocate_maxwell_fields_2d(mesh->K, p_Np, Hx, Hy, Ez);
The call to the function seems to go fine, but when I get a segmentation
fault when i try to access for example Hx[0] after I called the allocation
function. Apparently, after the call to my allocate function, the Hx pointer
is not correctly set.
What am I doing wrong here?
Thanks!
Bart
I do:
I declare the three vectors as pointers to doubles:
double *Hx;
double *Hy;
double *Ez;
I then have the function that allocates the memory for the
vectors:
void allocate_maxwell_fields_2d(int K, int Np,
double *Hx, double *Hy, double *Ez) {
Hx = (double*) calloc(K*Np, sizeof(double));
Hy = (double*) calloc(K*Np, sizeof(double));
Ez = (double*) calloc(K*Np, sizeof(double));
}
And I call the function as follows:
allocate_maxwell_fields_2d(mesh->K, p_Np, Hx, Hy, Ez);
The call to the function seems to go fine, but when I get a segmentation
fault when i try to access for example Hx[0] after I called the allocation
function. Apparently, after the call to my allocate function, the Hx pointer
is not correctly set.
What am I doing wrong here?
Thanks!
Bart