Guard against unsafe usage of QFrameAllocator::(de)allocateRawMemory.

Before one could potentially fall into a trap when one would call

allocateRawMemory<BaseClass>(size);

When size belongs to a child class inheriting from BaseClass and
falls into a different (larger) bucket, the following deallocation
via

deallocateRawMemory<BaseClass>()

would fail. Because there we just picked the size of the BaseClass
to find the bucket.

Now the whole API is restructured to guard against this wrong usage:

- we only ever operator on void* in the *Raw* methods
- we pass on the size explictily

This also means we must use the safe operator deallocate overloads
that also take the size as a parameter.

The unit test was run first to check that this was indeed an issue.
Then it is ported to the new API and cleanup up a bit as well to
reduce duplicated code.

Change-Id: I559af1c0ffc633962fac12d6e3cadf87c09ef92d
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Add benchmark suite for QFrameAllocator.

Results for instr:k perf counter on my machine are:

********* Start testing of tst_QFrameAllocator *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC
4.9.2)
PASS   : tst_QFrameAllocator::initTestCase()
PASS   : tst_QFrameAllocator::benchmarkAllocateSmall()
RESULT : tst_QFrameAllocator::benchmarkAllocateSmall():
     1,060,442 instructions per iteration (total: 1,060,442, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateBig()
RESULT : tst_QFrameAllocator::benchmarkAllocateBig():
     1,145,940 instructions per iteration (total: 1,145,940, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateSmall()
RESULT : tst_QFrameAllocator::benchmarkDeallocateSmall():
     901,579 instructions per iteration (total: 901,579, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateBig()
RESULT : tst_QFrameAllocator::benchmarkDeallocateBig():
     901,579 instructions per iteration (total: 901,579, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateRaw()
RESULT : tst_QFrameAllocator::benchmarkAllocateRaw():
     1,067,539 instructions per iteration (total: 1,067,539, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateRaw()
RESULT : tst_QFrameAllocator::benchmarkDeallocateRaw():
     971,701 instructions per iteration (total: 971,701, iterations: 1)
PASS   : tst_QFrameAllocator::cleanupTestCase()
Totals: 8 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of tst_QFrameAllocator *********

Change-Id: Iae2bcd53d4efcff4b8486b4571dc1d1acfcbc19d
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Enforce that we never try to allocate unexpectedly huge items.

This also allows us to greatly simplify the code while at it.

If future subclasses ever become larger than our maxObjectSize,
we can either force them to overload operator new themselves
or increase the maxObjectSize in the allocator.

That never happens in practice and just increases the codesize
and also slows down the code. The benchmark now shows the following
numbers for perf's instr:k counter on my machine:

********* Start testing of tst_QFrameAllocator *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC
4.9.2)
PASS   : tst_QFrameAllocator::initTestCase()
PASS   : tst_QFrameAllocator::benchmarkAllocateSmall()
RESULT : tst_QFrameAllocator::benchmarkAllocateSmall():
     880,438 instructions per iteration (total: 880,438, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateBig()
RESULT : tst_QFrameAllocator::benchmarkAllocateBig():
     965,937 instructions per iteration (total: 965,937, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateSmall()
RESULT : tst_QFrameAllocator::benchmarkDeallocateSmall():
     701,573 instructions per iteration (total: 701,573, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateBig()
RESULT : tst_QFrameAllocator::benchmarkDeallocateBig():
     701,572 instructions per iteration (total: 701,572, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateRaw()
RESULT : tst_QFrameAllocator::benchmarkAllocateRaw():
     867,893 instructions per iteration (total: 867,893, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateRaw()
RESULT : tst_QFrameAllocator::benchmarkDeallocateRaw():
     771,701 instructions per iteration (total: 771,701, iterations: 1)
PASS   : tst_QFrameAllocator::cleanupTestCase()
Totals: 8 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of tst_QFrameAllocator *********

Change-Id: I0500a206e8460e27b5157d6238a06bee355b7318
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Cleanup and hide more of the QFrameAllocator implementation.

This also allows the compiler to inline some more code leading to
a slight performance gain in the benchmarks:

********* Start testing of tst_QFrameAllocator *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC
4.9.2)
PASS   : tst_QFrameAllocator::initTestCase()
PASS   : tst_QFrameAllocator::benchmarkAllocateSmall()
RESULT : tst_QFrameAllocator::benchmarkAllocateSmall():
     830,448 instructions per iteration (total: 830,448, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateBig()
RESULT : tst_QFrameAllocator::benchmarkAllocateBig():
     916,006 instructions per iteration (total: 916,006, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateSmall()
RESULT : tst_QFrameAllocator::benchmarkDeallocateSmall():
     641,572 instructions per iteration (total: 641,572, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateBig()
RESULT : tst_QFrameAllocator::benchmarkDeallocateBig():
     641,573 instructions per iteration (total: 641,573, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkAllocateRaw()
RESULT : tst_QFrameAllocator::benchmarkAllocateRaw():
     827,544 instructions per iteration (total: 827,544, iterations: 1)
PASS   : tst_QFrameAllocator::benchmarkDeallocateRaw()
RESULT : tst_QFrameAllocator::benchmarkDeallocateRaw():
     721,701 instructions per iteration (total: 721,701, iterations: 1)
PASS   : tst_QFrameAllocator::cleanupTestCase()
Totals: 8 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of tst_QFrameAllocator *********

Change-Id: Id1f314182aa8257eba15179e3567f303f7bb9ef1
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>