Skip to content

[BUG] extra memory copy in bitmap operate #5855

Description

@stdpain

Describe the bug

When we traverse the bitmap value, there may be performance or memory issues due to the extra memory copies.
It was caused by mismatched lambda expression parameters
eg:

#include<algorithm>
#include<iostream>
#include<map>structMC {
MC() = default;
MC(constMC& r) { std::cout << "call copy construct" << std::endl; }
size_twrite(char*) const { return0; }
int ans;
};
intmain() {
MC mc0;
std::map<int, MC> st;
using iter = std::map<int, MC>::iterator;
st[0] = mc0;
st[1] = mc0;
std::cout << "start test" << std::endl;
char mem_buffer[4096];
char* buf = mem_buffer;
std::for_each(st.cbegin(), st.cend(), [&buf](const std::pair<constint, MC>& map_entry) {
buf += map_entry.second.write(buf);
});
std::cout << "start test 2" << std::endl;
std::for_each(st.cbegin(), st.cend(), [&buf](const std::pair<int, MC>& map_entry) {
buf += map_entry.second.write(buf);
});
return0;
}

output:

start test
start test 2
call copy construct
call copy construct

so we should make std::pair<uint32_t,RoarMap> to std::pair<const uint32_t,RoarMap>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions