음악, 삶, 개발

vector 를 사용할때 고려해야할것 본문

개발 공부/C++ 약점공략

vector 를 사용할때 고려해야할것

Lee_____ 2020. 10. 24. 02:34

vector 가 가지고있을 클래스의 크기를 고려해야한다.

이 클래스가 매우 거대하다면,

1개를 지우려고하면, 다른 요소들을 하나씩 좌측으로 옮기기위해

수많은 Move Assignment 함수를 호출해버리는 erase() 같은 함수는,

나의 프로그램의 큰 성능 저하를 가져올수있기때문이다.

이에 대해 Peter 와 대화를 나누었고 아래와 같은 대답을 하였다.

 

< Peter 왈 > 

 

When a class is 128 bits or less, it’s cheaper to pass by value than reference is the guideline I’ve heard.

The smaller something is, the cheaper it is to do operations on it (usually).

But this is micro-optimization.

I’d say get some version of it running, and then see where the performance problems are.

If you don’t have a UUID, you’re probably going to run into some problems that are pretty nasty to solve without it.

 

일단 돌아가는 프로그램을 만들고 그때가서 걱정하라고 말씀하였다..