2021年3月3日星期三

Reset directly the content of a pointer to a struct

I have implemented a function that resets the content of the pointer to a structure:

template <typename Struct>  void initialize(Struct* s)  {      *s = Struct{};  }  

I have performance issues when Struct becomes big (above 10K) because Struct is created in the stack and then assigned to *s. I was wondering if I could improve it:

  1. Is it possible to initialize directly *s without the temporary Struct{} object?
  2. Should I instead evaluate the size of Struct and build it in the heap if it is big?

Thank you in advance

https://stackoverflow.com/questions/66467465/reset-directly-the-content-of-a-pointer-to-a-struct March 04, 2021 at 09:52AM

没有评论:

发表评论