Add option CONTAINER_INITIAL_ALLOC_ZERO_SLACK to disable array slack, for easier toggling if there are issues, or per-project toggling. Check in disabled for now

#rb steve.robb


#ROBOMERGE-SOURCE: CL 11301902 via CL 11301903 via CL 11301904 via CL 11301905
#ROBOMERGE-BOT: (v649-11301724)

[CL 11301906 by ben woodhouse in Main branch]
This commit is contained in:
ben woodhouse
2020-02-09 13:38:38 -05:00
parent e864c7a6cc
commit 6c0213dcbc

View File

@@ -11,6 +11,13 @@
#include "Math/NumericLimits.h"
#include "Templates/IsPolymorphic.h"
// This option disables array slack for initial allocations, e.g where TArray::SetNum
// is called. This tends to save a lot of memory with almost no measured performance cost.
// NOTE: This can cause latent memory corruption issues to become more prominent
#ifndef CONTAINER_INITIAL_ALLOC_ZERO_SLACK
#define CONTAINER_INITIAL_ALLOC_ZERO_SLACK 0
#endif
class FDefaultBitArrayAllocator;
template<int IndexSize> class TSizedDefaultAllocator;
@@ -76,11 +83,24 @@ FORCEINLINE SizeType DefaultCalculateSlackGrow(SizeType NumElements, SizeType Nu
checkSlow(NumElements > NumAllocatedElements && NumElements > 0);
SIZE_T Grow = FirstGrow; // this is the amount for the first alloc
#if CONTAINER_INITIAL_ALLOC_ZERO_SLACK
if (NumAllocatedElements)
{
// Allocate slack for the array proportional to its size.
Grow = SIZE_T(NumElements) + 3 * SIZE_T(NumElements) / 8 + ConstantGrow;
}
else if (SIZE_T(NumElements) > Grow)
{
Grow = SIZE_T(NumElements);
}
#else
if (NumAllocatedElements || SIZE_T(NumElements) > Grow)
{
// Allocate slack for the array proportional to its size.
Grow = SIZE_T(NumElements) + 3 * SIZE_T(NumElements) / 8 + ConstantGrow;
}
#endif
if (bAllowQuantize)
{
Retval = (SizeType)(FMemory::QuantizeSize(Grow * BytesPerElement, Alignment) / BytesPerElement);