General strategies for memory/speed problems

后端 未结 4 1742
春和景丽
春和景丽 2021-01-21 23:05

I have a c++ code which runs through about 200 ASCII files, does some basic data processing, and outputs a single ASCII file with (basically) all of the data.

The progra

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 23:56

    This is a total shot in the dark. You've got:

    bool getDirectoryContents(const string dirName, vector *conts) {
        ...
        copy(directory_iterator(p), directory_iterator(), back_inserter(v));
    

    How does the performance change if you instead make that:

    bool getDirectoryContents(const string dirName, vector *conts) {
        ...
        // note: preincrementing the iterator
        for (directory_iterator it((p)); it!=directory_iterator(); ++it) {
           v.push_back(*it);
        }
    

    My thought is that std::copy is specified to use postincrement. And boost::filesystem::directory_iterator is an InputIterator: it shouldn't really support postincrement. boost::filesystem::directory_iterator may not be happy being postincremented.

提交回复
热议问题