for (int i = 0; i < samplesPerBlock; i++) {
Memory<float> memory(deviceGPU, fdmMeshN);
If you do this, the memory will be created & destroyed per loop (but you want to keep the memory). You may use std::unique_ptr. BTW, I am not sure whether frequent memory allocation on the audio thread will work for your case perhaps it is unavoidable for GPU?
This Memory structure represents an equal amount of memory generated in parallel on the GPU and CPU. It is very handy for copying things back and forth.
Yeah I presumed something is getting garbage collected. But why? Doesn’t
Yes it is. But the memory get destroyed per loop, i.e., the memories will become a vector of meaningless pointers outside the loop.
I would do this:
std::vector<std::unique_ptr<Memory<float>>> memories;
for (int i = 0; i < samplesPerBlock; i++) {
memories.emplace_back(std::make_unique<Memory<float>>(deviceGPU, fdmMeshN);
std::vector<std::shared_ptr<Memory<float>>> memoryList;
memoryList.emplace_back(fdmG);
memoryList.emplace_back(fdmG_1);
for (int i = 0; i < memoryList.size(); i++) {
auto memPtr = std::make_shared<Memory<float>>(deviceGPU, fdmMeshN);
memoryList[i] = memPtr;
if (i == 0) {
DBG(" FDMG LENGTH " << fdmG->length()); //DOESN'T WORK
DBG(" 0 LENGTH " << memoryList[i]->length()); //WORKS
}
}
The memoryList gets a working pointer to the new Memory object. However, the fdmG object is still pointing at nothing. The whole point of the temporary memoryList object is I wanted to update the private pointers like fdmG without having to go through them one by one.
Is there any way to make this code update fdmG at the same time? Ie. from some type of list?
Hypothetically, if memoryList was 20+ entries long, I don’t want to update all the private objects one by one. I want to put them in that big list and iterate through to make my life easier.
But this is not updating the core private elements. Do I need to make some type of reference list or what?