What is faster when creating 100+ newObjs:
//initialization list
struct struct_Obj {
...tonsOfVars
struct_Obj() : tonsOfVars(init) {}
}
Or:
//static const already constructed, call the copy constructor(?)
static const struct_Obj defaultStruct_Obj = { tonsOfVars(init) };
struct_Obj newObj = defaultStruct_Obj
TonsOfVars would imply multiple different variables (from POD to structs/classes)
I would assume static const, since its calling the copy constructor (meaning 1 op?) vs calling each initializer in the initalization list?
Although the common response for this is "profile it", even doing so would not give me an explanation WHY it is faster.
It really depends on the types in
tonsOfVars.It is calling one copy constructor for
struct_Obj, but it still needs to call copy constructor for each field.If they all are POD data, there would be no difference at all. However, in some types default constructors may be faster (or slower) than copy constructors, so that would make a difference.