Page 1 of 1
vector<string> MLE ~50MB
Posted: Wed Aug 30, 2006 5:56 pm
by nev4
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?
Re: vector<string> MLE ~50MB
Posted: Wed Aug 30, 2006 10:49 pm
by Krzysztof Duleba
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).
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:
Code: Select all
template<typename T>
inline void really_clear_vector(vector<T> &v) {
vector<T> tmp;
swap(v, tmp);
}
The important thing is that tmp is local in the function scope and will be destroyed when no longer needed.
Note that assigning an empty vector to v has the same effect as clear.
nev4 wrote:Can i use size_t instead of string::size_type for string::npos determing?
You shouldn't, but it will work in most cases (int will work too, at least on 32-bit architectures).