hi i have the following code…
int *a, *b;
int *d;
int N = 2000;
size_t size = N*sizeof(int);
a = (int *) malloc(size);
b = (int *) malloc(size);
...
cudaMalloc((void **) &d, size);
it works just fine… now assume I have the following
char **t = malloc(2000* sizeof *t);
for(...)
{
...
t[i] = (char *)malloc(sizeof(char)*changing_length);
...
}
how to do cudaMalloc for t as if it is one dimensional array (taking into account that each element has different size) ?
If you have a regular 2D array of chars you can calculate the size with…
If you have an irregular 2D array (some rows have different lengths) then you’ll have to either keep track of the total number of chars somewhere else or loop through and count how many chars you have before you do the cudaMalloc.