|
|
|
|||||
|
problem with string sequences
There seems to be a problem in implementing out parameter for string sequences:
void IceInternal::BasicStream::read(vector<string>& v) { Int sz; readSize(sz); while(sz--) { string s; read(s); v.push_back(s); } } Vector is not cleared, therefore it just keeps growing, causing memory problems in client code like : Test::AStruct input,output; for (int i=0; i<num_elems; ++i) { input.iseq.push_back(i); input.sseq.push_back("abcd"); } for (int i=0;i<num_calls;++i) { twoway->foo(input,output); } Time after = Time::now(); If we change BasicStream::read as : void IceInternal::BasicStream::read(vector<string>& v) { Int sz; readSize(sz); v.clear(); v.reserve(sz); while(sz--) { string s; read(s); v.push_back(s); } } problem goes away. |
|
|||||
|
Hello,
I had been working a bit on improving performance when passing lots of string sequences and I came up with another version which might be of some interest: Code:
void
IceInternal::BasicStream::read(vector<string>& v)
{
Int sz;
readSize(sz);
std::vector<std::string> result(sz);
std::vector<std::string>::iterator it = result.begin();
std::vector<std::string>::iterator const end = result.end();
for(; it != end; ++it)
{
read(*it);
}
v.swap(result);
}
Cheers, Bertrand. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| No sequences of objects in Ice-E? | bartley | Help Center | 5 | 05-30-2006 06:44 PM |
| IcePy, large sequences | huberthoegl | Help Center | 6 | 01-11-2006 05:19 AM |
| Link problem using a string to class map | MKoleoso | Help Center | 2 | 07-03-2005 12:02 PM |
| problem in mapping string->string[] in C# | teayu | Help Center | 2 | 10-27-2004 12:12 AM |
| sequences syntax | panic | Help Center | 1 | 12-04-2003 09:55 AM |