Hello, As there was no reply to this my mail in roottalk, I will reply myself. The problem was following. TMap defines a map between pointers to objects and does not alow to define a map between values of objects: ( MyKey*, MyObject* ) - is ok for TMap ( MyKey , MyObject* ) cannot be filled in TMap When passing from ( MyKey , MyObject* ) to ( MyKey*, MyObject* ), the searching algorithm: map.find(SomeKey) cannot be used and map.find(SomeKey*) is not what we need. So iterating over all elements in the map and comparing MyKey values was needed. The workaround was to use TExMap which alows to map ( Long_t, Long_t ) and to define conversion functions between my key values and Long_t and back and to cast Longt_t to MyObject* when needed; so finally this worked (without a performence penalty): Filling the map: ( GetIndex(MyKey), (Long_t)MyObject* ) Searching in the map: (MyObject*) map.GetValue(GetIndex(MyKey)) Thanks to Victor Perevoztchikov who pointed me to this solution. Best regards, Ivana Hrivnacova ============================================================== e-mail: Ivana.Hrivnacova@cern.ch address: Institut Physique Nucleaire, 91406 Orsay, France phone: (33) 01 69 15 65 94 ============================================================== On Tue, 7 Oct 2003, Ivana Hrivnacova wrote: > > Hello, > > The change of std::map to TMap in our code has > caused a perfomance penalty by factor 4 for our test. > That's why I'd like to understand if > TMap was used in an optimal way. > > The description what has been done is below, > the full class is in the attachement. > (It would take more time to extract the problem into > a simpler example and to reproduce the problem in it.) > > Thank you. > > Versions: Root 3.05.07, gcc 3.1 > > Ivana Hrivnacova > > ----- > > The map is defined as: > STL: > typedef map<AliMpIntPair, AliMpConnection*> ConnectionMap_t; > typedef ConnectionMap_t::const_iterator ConnectionMapCIterator; > ConnectionMap_t fConnections; //! Map (ix,iy) of connections > > Root: > typedef TMap ConnectionMap_t; > typedef TMapIter ConnectionMapCIterator; > ConnectionMap_t fConnections; //! Map (ix,iy) of connections > > The map is filled by > (it is filled only once in the program): > const AliMpIntPair& localIndices; > AliMpConnection* connection; > fConnections[localIndices]=connection; // STL > fConnections.Add(new AliMpIntPair(localIndices), connection); //Root > > The search by a key is performed as: > #ifdef WITH_STL > ConnectionMapCIterator i = fConnections.find(localIndices); > if (i != fConnections.end()) > return i->second; > else > return 0; > #endif > > #ifdef WITH_ROOT > AliMpIntPair* key; > ConnectionMapCIterator i(&fConnections); > while ((key = (AliMpIntPair*)i.Next())) { > if (*key == localIndices) > return (AliMpConnection*)fConnections.GetValue(key); > } > return 0; > #endif > > The search by various characteristics of AliMpConnection > is performed as: > #ifdef WITH_STL > for (ConnectionMapCIterator i = fConnections.begin(); i!=fConnections.end();++i) > if (i->second->GetGassiNum()==gassiNum) return i->second; > #endif > > #ifdef WITH_ROOT > TObject* key; > AliMpConnection* connection; > ConnectionMapCIterator i(&fConnections); > while ((key = i.Next())) { > connection = (AliMpConnection*)fConnections.GetValue(key); > if (connection->GetGassiNum()==gassiNum) return connection; > } > #endif > > --
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET