In all problems where i try to use this i get Memory Limit Exceeded. I clear vector for every next case, but no effect. I'm used to get 49632 kilobytes (as tried deque instead were ~33MB) in every problem when i'm using this combo, even if problem description guarantees only up 6MB (100 strings * 60 chars or 40 strings * 40 chars).
Can i use size_t instead of string::size_type for string::npos determing?
vector<string> MLE ~50MB
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Re: vector<string> MLE ~50MB
Clear doesn't really work on vectors - it sets size to 0, but capacity remains unchanged. You have to swap a vector with an empty one:nev4 wrote:In all problems where i try to use this i get Memory Limit Exceeded. I clear vector for every next case, but no effect. I'm used to get 49632 kilobytes (as tried deque instead were ~33MB) in every problem when i'm using this combo, even if problem description guarantees only up 6MB (100 strings * 60 chars or 40 strings * 40 chars).
Code: Select all
template<typename T>
inline void really_clear_vector(vector<T> &v) {
vector<T> tmp;
swap(v, tmp);
}
Note that assigning an empty vector to v has the same effect as clear.
You shouldn't, but it will work in most cases (int will work too, at least on 32-bit architectures).nev4 wrote:Can i use size_t instead of string::size_type for string::npos determing?
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...