cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.87k stars 1.69k forks source link

Using std::variant as element type #336

Closed PhilippPaetzold closed 1 year ago

PhilippPaetzold commented 1 year ago

Hi,

I want to use the blockingconcurrentqueue and enqueue/dequeue different types. I want store multiple elements each being one instance of 5-10 different DTOs, with 10 floats in some and with an std::array<int, 256> in others. I would like to use std::variant for that purpose with an std::visitor on the dequeueing side. Compilation works so far in a simple test project. Is there anything to consider here? What about performance and how is the queue pre-allocated in this case? It would be great if I could control heap allocations by using preallocation during initialization and avoid hidden heap allocations in my application if possible.

@cameron314, it would be nice, if you could give me your opinion on that?

Thank you

cameron314 commented 1 year ago

Preallocation is mostly covered in the README.

Using elements that are 1+ KB will not be particularly efficient, but it's all dependent on your particular use case. I would suggest benchmarking.

PhilippPaetzold commented 1 year ago

@cameron314: Thank you, I will try to avoid hitting 1024 Bytes per DTO then and do some benchmarking to make sure it performs well.