On Wed, Feb 12, 2020 at 05:05:25PM +0100, Pavel Sanda wrote: > On Wed, Feb 12, 2020 at 08:50:13AM -0500, Scott Kostyshak wrote: > > Is it true that without optimization, this change would be less > > efficient because cell has to be recreated (so memory allocated) on each > > iteration of the for loop? But is the idea that compilers recognize this > > and only allocate memory once so that in practice there is no loss in > > efficiency? > > I am no expert of what nowadays compilers do in backgrounds but if the > variable > was a simple type like integer then there is really no memory allocation > business going on, because you are on stack. Stack pointer might decrease, > that > should be all. > Contrary is the case when you get new variable on heap via new/malloc/... > > When the variable is class I can imagine things could go south when > someone would define copy constructor and assignment operator with > strikingly different semantics. But then again, the issue is not > inherently with memory allocation per se...
Good to know. This gives me some things to think about and search for more information if I want to follow-up on this (just as a motivating reason to learn more about a couple of "lower level" topics in C++). Thanks, Scott
signature.asc
Description: PGP signature
-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel