Search code examples
c++memory-managementarrayfire

arrayfire, pointers, and c++


I have been trying to procedurally generate an array of arrayfire arrays. When dealing with other objects in the past I could either so something like:

className * listName = (className*)malloc(numOfObjects*sizeOf(className))

or

className ** listName = (className**)malloc(numOfObjects*sizeOf(className*))

and then use a for loop to allocate each of the things in the lists and delete them when I'm done with them.

This isn't working with arrayfire however. I have tried to do

af::array *Kernels; 
Kernels = (af::array*)malloc(Count*sizeof(af::array)); 

for(int i = 0; i < Count; i++) {
    Kernels[i] = af::range(i); 
}

Later I call:

free Kernels

This code compiles but will crash when I run it. This is what I get when it crashes:

terminate called after throwing an instance of 'af::exception' what(): ArrayFire Exception (Function does not support this data type:204): In function af_err af_release_array(af_array) In file src/api/c/array.cpp:194 Invalid type for argument 0

In function af::array& af::array::operator=(const af::array&) In file src/api/cpp/array.cpp:771 Aborted (core dumped)

I'm looking for either the correct syntax to do what I am trying to do or an alternative. I have googled around quite a bit and have not found what I am looking for.

Thanks.


Solution

  • So it seems like I have finally gotten a solution. It seems like using this: std::vector<af::array> Kernels; gets me all the functionality I want. It turns out that having a double pointer will compile but the functions in arrayfire are not built to deal with af::array* object pointers.