Why does compiling over 100,000 lines of std::vector::push_back take a long time?

前端 未结 3 2010
天命终不由人
天命终不由人 2021-02-01 06:01

I\'m compiling a C++ library which defines a single function that randomly samples from a set of data points. The data points are stored in a std::vector. There a

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 06:54

    I believe the long time relates to vector being a template. The compiler needs to rewrite every occurance of push_back with the corresponding function. It's like having many overloaded functions, where the compile needs to do name mangling to address the correct function. This is an extra work compared to simply compiling non-overloaded functions.

提交回复
热议问题