我正在努力解决自定义分配器的性能问题。我的问题是关于调试版本。
通常情况下,如果只有一点点下降我并不介意。但目前我正在以 4fps 播放某些内容,而如果没有自定义分配器,则播放速度为 60fps(并且可能会更快)。这使得软件开发变得更加困难。
我一直把它确定下来......基本上继承了标准分配器
请参阅“quick-bench.com”的以下结果 https://quick-bench.com/q/ep3uyYNK6rh_6f8AGAP0zIAflAA
蓝色条很简单:
int main() {
std::vector<uint8_t, std::vector<uint8_t>::allocator_type> buffer;
buffer.reserve(numBytes);
buffer.resize(numBytes);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
黄色条:
template<typename T>
class CustomAllocatorType : public std::vector<uint8_t>::allocator_type {};
int main() {
std::vector<uint8_t, CustomAllocatorType<uint8_t>> buffer;
buffer.reserve(numBytes);
buffer.resize(numBytes);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用以下内容封装自定义分配器:
#pragma GCC push_options
#pragma GCC optimize ("-O3")
// ....
#pragma GCC pop_options
Run Code Online (Sandbox Code Playgroud)
没有任何效果。我想我需要对向量实例本身执行此操作,但我不想走那么远......
有谁知道这个问题的解决方案?