05-29-2015 04:03 PM
I have a C dll that is acquiring frames of data and putting them in a 1D array of doubles and returning a pointer to the array. Since I know how many doubles I asked for, I know how big the returned array will be. I then used the GetValueByPointer.xnode to read my array from this memory location. The C dll allocated the memory space and keeps using it on every subsequent call. So while I keep getting the pointer passed on every call, it isn't changing or reallocating memory in the C dll. I have to keep calling this function though as it provides the syncing for my loop to tell me when new data is available to be read from memory. Here was my code:
I tried all sorts of things including preallocating the 1-D array, putting it into a shift register and then replacing what was in the shift register with my data. I even left the output terminals unwired. In all cases, I watched my memory slowly count upwards. My program worked, but it came with a time bomb that would kill it eventually.
Then I switched to this with the moveblock node:
My memory usage is now stable when running. What was causing the getvaluebypointer.xnode implementation to keep consumming memory?
I have my solution and am very happy with it. I guess this is just a cautionary tale regarding the xnode. I read all I could find on it. The other negative I found somewhere was that it runs in the UI thread. Very bad. That would have killed me eventually because this code will eventually get segregated into its own thread and will be set to high priority to ensure that I am always ready to receive the next frame of data since I loose frames when I am not able to read before the dll write the next frame to memory. Putting a function in this loop in the UI thread is a no-go. Luckily, I get to choose the thread with MoveBlock.
Have a good weekend all.
-Chris.