hello,everyone.
I’m confused about which initialization method performs best.I wish I could learn something better
for example:
struct FDog
{
FVector Postion;
double Health;
}
// example A:Initialize variables
void FunctionA()
{
// MethodA
FDog DogA{FVector{0.f, 0.f, 0.f}, 100.f};
// MethodB
FDog DogB;
DogB.Postion = FVector{0.f, 0.f, 0.f};
DogB.Health = 100.f;
// Which of the above initializations is better?
};
// example B:TArray Add elements
void FunctionB()
{
// MethodA
TArray<FDog> Dogs;
int8 I = Dogs.Emplace();
FDog& DogA = Dogs[I];
DogA.Postion = FVector{0.f, 0.f, 0.f};
DogA.Health = 100.f;
// MethodB
FDog DogB{FVector{0.f, 0.f, 0.f}, 100.f};
Dogs.Emplace(DogB);
// Which of the above initializations is better?
};