Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22018

Performance with dynamically sized arrays in C++ MSVC vs GCC [duplicate]

$
0
0

Today a little argument erupted over the following code line in a fairly time critical piece of C++ that was running.

void func(std::string& str)
{
    ...
    uint8_t buffer[str.size() + 10];
    ...
}

Now obviously you can compile this in C as the standard supports dynamically sized arrays. However GCC C++ seems to allow this kind of construct through some kind of an extension. MSVC doesn't allow this kind of statement, so we were a bit puzzled.

  • Does GCC allocate it at declaration time and is this allocation done on the stack? Is it syntactic sugar for a dynamic allocation, like say using new to create an array?

  • Is there are performance penalty for using a dynamically sized array over say a static one, given that a static one would be allocated in the prologue?


Viewing all articles
Browse latest Browse all 22018

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>