[ http://issues.apache.org/jira/browse/TUSCANY-946?page=comments#action_12456953 ] Geoff Winn commented on TUSCANY-946: ------------------------------------
Patch applied. > std::string usage in DataFactoryImpl.cpp allocates/deallocates heap and copys > memoery too frequently > ---------------------------------------------------------------------------------------------------- > > Key: TUSCANY-946 > URL: http://issues.apache.org/jira/browse/TUSCANY-946 > Project: Tuscany > Issue Type: Improvement > Components: C++ SDO > Affects Versions: Cpp-current > Reporter: Yang ZHONG > Priority: Minor > Attachments: DataFactoryImpl.946 > > > Thanks to Geoffrey Winn and Pete Robbins; see the thread > http://www.mail-archive.com/tuscany-dev%40ws.apache.org/msg11015.html(Use > std::string as an example to discuss object vs. &/* to reduce heap > allocation/release and memory copying) > for more info. > Here's an example: > > typedef std::string SDOString; > SDOString DataFactoryImpl::getFullTypeName(const SDOString& uri, const > SDOString& inTypeName) const > { > return uri + "#" + inTypeName; > } > void DataFactoryImpl::addType(const char* pccUri, const char* > pccTypeName,...) > { > SDOString fullTypeName = getFullTypeName(pccUri, pccTypeName); > ... > } > > 1. getFullTypeName(pccUri,pccTypeName) call will allocate stack for > std::string instance uri and inTypeName. > Since a URI is likely longer than 16(see std::string implementation), a > heap(5-1) piece will be allocated. > pccUri and pccTypeName will be copied into uri(7-1) and inTypeName(7-2) > respectively > 2. uri+"#" will allocate stack and *heap*(5-2) for a new std::string > instance, and uri will be copied(7-3) > 3. ...+inTypeName will allocate stack and *heap*(5-3) for another new > std::string instance, and above(2.) std::string(7-4) and inTypeName(7-5) will > be copied > 4. getFullTypeName return will allocate stack and *heap*(5-4) for yet another > new std::string instance, and return value will be copied(7-6) > 5. The assignment to local variable fullTypeName, will allocate stack and > *heap*(5-5) for one more new std::string instance, and value will be > copied(7-7) > > It's too frequent that simple 2 lines of code allocate/deallocate heap *five* > times and copy memory *seven* times. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
