I need to create 10 of “ImageNPP_32f_C1”, store different images in them and keep their addresses in a structure for further access. My problem is that in each loop iteration, “myImage” always gets the same identical memory address! As a result all elements of “myArray” will have the same identical memory address.
Isn’t compiler supposed to allocate a new memory address for each iteration? Am I missing something?
Even if the underlying class constructor had allocations going on, that would not impact the address of the stack variable (i.e. the address of the object instantiated on the stack).
If you use the c++ new operator to instantiate your object at each iteration, it should fix your issue. The pointer returned by new should be unique for each iteration.
Oh, right, thank you so much. Keeping the address of a local variable wouldn’t work.
I think for my purpose I need to dynamically allocate memory via a “new” in each iteration. Can you please let me know how one would do it?
Oh, right, thank you so much. Keeping the address of a local variable wouldn’t work.
I think for my purpose I need to dynamically allocate memory via a “new” in each iteration. Can you please let me know how one would do it?