-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Description
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>
struct MC {
MC() = default;
MC(const MC& r) { std::cout << "call copy construct" << std::endl; }
size_t write(char*) const { return 0; }
int ans;
};
int main() {
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<const int, 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);
});
return 0;
}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>
Metadata
Metadata
Assignees
Labels
No labels