| 3420 | */ |
| 3421 | template <class DataType> |
| 3422 | void QCPDataContainer<DataType>::performAutoSqueeze() |
| 3423 | { |
| 3424 | const int totalAlloc = mData.capacity(); |
| 3425 | const int postAllocSize = totalAlloc-mData.size(); |
| 3426 | const int usedSize = size(); |
| 3427 | bool shrinkPostAllocation = false; |
| 3428 | bool shrinkPreAllocation = false; |
| 3429 | if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size |
| 3430 | { |
| 3431 | shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! |
| 3432 | shrinkPreAllocation = mPreallocSize*10 > usedSize; |
| 3433 | } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother |
| 3434 | { |
| 3435 | shrinkPostAllocation = postAllocSize > usedSize*5; |
| 3436 | shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller |
| 3437 | } |
| 3438 | |
| 3439 | if (shrinkPreAllocation || shrinkPostAllocation) |
| 3440 | squeeze(shrinkPreAllocation, shrinkPostAllocation); |
| 3441 | } |
| 3442 | |
| 3443 | |
| 3444 | /* end of 'src/datacontainer.h' */ |