Re: Proposing automatic move in static arrays element creation
to get huge speed boost
{ Reformatted; please limit your lines to 70 characters, and do not
insert blank lines in quoted sections -mod }
Skyscrapper city[1000]; // instead of temp
city[1] = Skyscrapper("Empire State Building"); // compiller should use
// &city[1] as this
pointer
This would fix heap and static(which && can't) waste = zero
alloc/copy. Majority of objects are small thus majority of their
memory is static.
This is one of the problems with RAII. Sometimes you want to create
the storage space and then initialize later when you have the
necessary runtime information for the constructor.
This is why I like to make my default constructors only initialize
pointers/resources to null. You can write an init() function to
actually construct the Skyscrapper later.
Skyscraper city[1000];
city[1].init("Empire State Building");
If you have to use constructors, here's a more hashish solution:
public header file:
extern Skyscraper* city;
const int city_size = 1000;
private cpp file:
static unsigned char alignas(Skyscraper) _city[sizeof(Skyscraper) *
city_size]
Skyscraper* city = reinterpret_cast<Skyscraper>(_city);
new (&city[1]) Skyscraper("Empire State Building");
But now its up to you to manually destruct the objects later. I
wouldn't go there unless you measured and found out that this is
really hurting performance.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]