It looks like ArrayAllocationBase.h has been recently replaced by ArrayBase.h, exhibiting some long awaited (at least by me!) performance boosts.
If you have some simple struct (or a class) like this e.g.
struct MyStruct
{
MyStruct(int sample_, float value_)
: sample(sample_)
, value(value_)
{}
int sample = 1;
float value = 2.0f;
};
and some arrays like Array<MyStruct> array1, array2;
and want to add them with
array1.addArray(array2)
the copy handling code in Array will now eventually boil down to
memcpy(elements + numUsed, otherElements, (size_t)numElements * sizeof(ElementType));
instead of previously a loop like
auto* start = elements + numUsed;
while (--numElements >= 0)
new (start++) ElementType(*(otherElements++));
which certainly looks much slower when you’re adding, say some 10 000 automation events…
And it’s not just appending one array to another that’s speedier now. Also creating, inserts and other bulky operations will gain from the face lifted Array class (and OwnedArray).
But what about the destructor?
-Well, which copy method to use (memcpy or loop) is determined by checking
std::is_trivially_copyable<MyStruct>::value;
which evaluates to true if the class/struct is trivially copyable (and false if not).
And for a class to be trivially copyable it mustn’t have a destructor (there’s a few other criterias as well, google!) which means if you add even an empty destructor like
~MyStruct()
{
}
you’re stuck with the old tedious element by element copying. (Which by the way happened to me, I had an empty destructor for debugging purposes, and had forgotten to remove it or just optimistically thought it would be removed by the optimizer…)
So, if you’re a hard core Array user (and haven’t yet switched to std::vector<>) you might want to make the objects you stuff in the Array trivially copyable for some performance boost!