Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Total size of allocated memory by container
Peppy last edited by
Is there any way how to know the total amount of memory allocated by containers like QList? I wish I had an option to be able to have information about, just to compute how many things I can stick into some memory limit. I can closely estimate memory usage for basic containers like QList (which seems to be double-linked list) or QVector, but not the other containers.
In general no. QList is not really a linked list (QLinkedList is). It is a sorta vector-list hybrid that allocates chunks of the data as contiguous arrays. How many chunks there are, what is their overhead size, does it hold pointers to elements or optimizes small sized items by holding them in place, what is the alignment overhead - these are all implementation details that affect the size and there's no reliable way to estimate them, or even if you did, they might change in future versions.