syoon
1
i am trying to convert code 1 to code 2…
maybe i still don’t get C part. but, why is the second code not working?
isn’t ‘*’ for pointer?
any comments or advice please?
many thanks in well advance…
==========
code 1…
#define X 100
…
int c_d_test[X];
for(i=0; i<X; i++)
cudaMalloc((void **)&c_d_test[i], Ysizeof(int));
==========
code 2…
int X = 100
…
int c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
for(i=0; i<X; i++)
cudaMalloc((void **)&c_d_test[i], Ysizeof(int));
syoon
2
i am trying to convert code 1 to code 2…
maybe i still don’t get C part. but, why is the second code not working?
isn’t ‘*’ for pointer?
any comments or advice please?
many thanks in well advance…
==========
code 1…
#define X 100
…
int c_d_test[X];
for(i=0; i<X; i++)
cudaMalloc((void **)&c_d_test[i], Ysizeof(int));
==========
code 2…
int X = 100
…
int c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
for(i=0; i<X; i++)
cudaMalloc((void **)&c_d_test[i], Ysizeof(int));
tera
3
Make that
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
for(int i=0; i<X; i++)
cudaMalloc((void **)&(c_d_test[i]), Y*sizeof(int));
tera
4
Make that
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
for(int i=0; i<X; i++)
cudaMalloc((void **)&(c_d_test[i]), Y*sizeof(int));
syoon
5
by trial&error, i figured it must be
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
instead of
int *c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
but, why?
is it because i am going to use this temp array ‘c_d_test’ as pointers to pointers later in the code?
syoon
6
by trial&error, i figured it must be
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
instead of
int *c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
but, why?
is it because i am going to use this temp array ‘c_d_test’ as pointers to pointers later in the code?
ceearem
7
Correct. c_d_test is a pointer on an array of elements of type (int*) hence it is of type (int**).
ceearem
8
Correct. c_d_test is a pointer on an array of elements of type (int*) hence it is of type (int**).
code 1 was
int *c_d_test[100];
This defines and sets aside memory for an array of 100 int pointers.
You first tried
int *c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
which defines and sets aside memory for a single int pointer.
Thus you were successful with
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
code 1 was
int *c_d_test[100];
This defines and sets aside memory for an array of 100 int pointers.
You first tried
int *c_d_test;
c_d_test = (int ) malloc(Xsizeof(int));
which defines and sets aside memory for a single int pointer.
Thus you were successful with
int **c_d_test;
c_d_test = (int **) malloc(X*sizeof(int *));
syoon
11
thanks all.
its like a tail in my butt…circling around forever to catch the concept of “pointer” …ha ha ha
syoon
12
thanks all.
its like a tail in my butt…circling around forever to catch the concept of “pointer” …ha ha ha