Home > OS >  Best way to implement fixed size array in C
Best way to implement fixed size array in C

Time:05-22

I am trying to implement a fixed size array of 32 bit integers, but the size is determined at runtime so it has to be heap allocated. Would it be more efficient to use a c std::vector and use vector.reserve() or should I use the conventional way of doing it using new int32_t[size]? Additionally, would it be worth using a unique_ptr with the conventional method using new?

CodePudding user response:

You would just be re-implementing std::vector. Probably badly because it takes years to figure out all the little corner cases and implement them correctly.

  • Related