From e75c691d073a1e627db29294a0c12a55c67e3e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 28 Aug 2019 17:44:20 +0200 Subject: [PATCH] QArrayData: Don't allocate space we cannot use When reallocating we assume we will grow more and increase the size to the next power of 2. However, this might be a size where we end up with space we cannot take advantage of. Such as having 4 bytes free at the tail when we have 8 byte objects. The larger the objects are the greater the chance is that we will end up in this situation, and it would have a greater chance to leave big allocated chunks unused. Change-Id: Ifea3d92763c1bafd489b66605c741447e5a57d5a Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qarraydata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 234a44f6b6..36a221f728 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -143,7 +143,7 @@ qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t heade } result.elementCount = (bytes - unsigned(headerSize)) / unsigned(elementSize); - result.size = bytes; + result.size = result.elementCount * elementSize + headerSize; return result; }