I am trying to implement a history of structures--I want to maintain a list of them, with a given maximum size. As a new structure arrives, I want to remove the oldest, and add the new one. In other words, a FIFO.
I am using a QList. Until I reach my maximum size, as new data arrives, I malloc a structure, fill it, and list.prepend() the pointer to the list. Forgive me for mallocing structures instead of creating new objects, I am at heart a C programmer, and this is legacy code being fit into a new QT app.
Once I reach my maximum size, as new data arrives, I use list.takeLast(), and use the returned data (the pointer to my previously malloc'd structure) for my new data. I prepend that to the list. I am trying to avoid continual new memory allocation, as these operations happen quickly, and my program typically runs for many days.
While this appears to do what I want, I also seem to have a memory leak. Why would this be? Am I doing something really stupid?
Thanks for any help.
Bookmarks