State of “memset” functionality in C++ with modern compilers

前端 未结 12 1782
我寻月下人不归
我寻月下人不归 2021-02-12 16:03

Context:

A while ago, I stumbled upon this 2001 DDJ article by Alexandrescu: http://www.ddj.com/cpp/184403799

It\'s about comparing various ways to initialize

12条回答
  •  面向向阳花
    2021-02-12 16:09

    If memory is not a problem, then precreate a static buffer of the size you need, initialized to your value(s). As far as I know, both these compilers are optimizing compilers, so if you use a simple for-loop, the compiler should generate the optimum assembler-commands to copy the buffer across.

    If memory is a problem, use a smaller buffer & copy that accross at sizeof(..) offsets into the new buffer.

    HTH

提交回复
热议问题