c++ - Initialization List Vs Static Const Initializing -
what faster when creating 100+ newobjs:
//initialization list struct struct_obj { ...tonsofvars struct_obj() : tonsofvars(init) {} }
or:
//static const constructed, call copy constructor(?) static const struct_obj defaultstruct_obj = { tonsofvars(init) }; struct_obj newobj = defaultstruct_obj
tonsofvars imply multiple different variables (from pod structs/classes)
i assume static const, since calling copy constructor (meaning 1 op?) vs calling each initializer in initalization list?
although common response "profile it", doing not give me explanation why faster.
it depends on types in tonsofvars
.
i assume static const, since calling copy constructor (meaning 1 op?) vs calling each initializer in initalization list?
it calling 1 copy constructor struct_obj
, still needs call copy constructor each field.
if pod data, there no difference @ all. however, in types default constructors may faster (or slower) copy constructors, make difference.
Comments
Post a Comment