Search code examples
c++corbatao

ACE/TAO Performance Issue


ACE/TAO length() function is taking too much time. Since it is creating that much amount of memory using new operator at the time of setting the length. Anybody knows alternate to length function for just setting the lengths in TAO.

Thanks,


Solution

  • From Will Otte from the ATCD mailing list: I’m going to guess that you’ve got some code like this:

    while (something) {
        CORBA::ULong pos = seq.length ();
        seq.length (pos+1);
        seq[pos] = some_value;
    }
    

    and are observing that the performance is pretty bad compared to

    std::vector<foo> vec;
    while (something) {
        size_t pos = vec.size ();
        vec.resize (pos + 1);
        vec[pos] = foo (bar);  // or the much more succinct vec.push_back (foo (bar));
    }
    

    right?

    The answer is likely because your STL implementation is helping you out and providing geometric growth when you use resize. The C++ standard doesn’t have any requirements like that (for resize; push_back is guaranteed to grow geometrically), so you’ve likely been lucky and shouldn’t depend on that behavior.

    The TAO sequences don’t provide this for you, so if you repeatedly resize you’re going to see poor performance because every time you resize, you’re going to have to pay for an allocation of a new buffer and the time to copy all extant elements to the new underlying buffer.