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

不打扰是莪最后的温柔 提交于 2020-02-16 10:41:27

问题


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?

来源:https://stackoverflow.com/questions/60043739/performance-with-dynamically-sized-arrays-in-c-msvc-vs-gcc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!