Go Back   ZeroC Forums > Bug Reports

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 01-13-2004
alexs alexs is offline
Registered User
 
 
Join Date: Jan 2004
Location: New York, NY
Posts: 4
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.
Reply With Quote
  #2 (permalink)  
Old 01-13-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Welcome!

Thanks for the bug report, this will be corrected in the next release.

Take care,
- Mark
Reply With Quote
  #3 (permalink)  
Old 01-26-2004
TiB TiB is offline
Registered User
 
 
Join Date: Dec 2003
Location: Germany
Posts: 2
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);
}
This gave me a significant performance improvement (on my platform RH9 + gcc3.2.2) and has the advantage of leaving the vector in a consistent state if an exception is thrown.

Cheers,
Bertrand.
Reply With Quote
  #4 (permalink)  
Old 01-26-2004
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
Interesting idea, thanks for the suggestion! We will try this.
Reply With Quote
  #5 (permalink)  
Old 01-27-2004
rdilipk rdilipk is offline
Registered User
 
Name: Dilip Ranganathan
Organization: 3M
Project: None
 
Join Date: Jul 2003
Location: Minnesota, USA
Posts: 35
The swap trick is mentioned in Effective STL by Scott Meyers to reduce the size of the vector.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -4. The time now is 08:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.