Forum Replies Created
-
AuthorPosts
-
::
Polymorphic allocators are a relatively unknown C++17 feature. You should use them if you need a high degree of control over memory management. I have already written three articles on this topic:
10. September 2025 at 15:52 in reply to: Should one have virtual and override in the same function declaration? #639604::Since C++17, the length of a std::array can be determined very easily:
#include <array> int main(){ std::array<int, 4> nums{1, 3, 5, 7}; constexpr auto n = nums.size(); }
There are a few problems with the following concept:
template<typename T> concept LargeStdArray = requires { typename T::value_type; { T{}.size() } -> std::convertible_to<std::size_t>; } && (T{}.size() >= 10);
- typename T::value_type: the type requirement is not specific enough, as it applies to all containers in the Standard Template Library.
- { T{}.size() } -> std::convertible_to<std::size_t>: the compound requirement is superfluous.
- LargeStdArray: the concept is far too specific. The standard already has the right concepts. In this case, the concept std::contiguous_range is appropriate.
12. May 2025 at 19:17 in reply to: Behaviour of global static, thread-local, atomic variables in multi-threading #638301::Before I answer the question, I have two general comments.
- It is usually not a good idea to work directly on a shared variable. It is often a good idea to use a local variable. Only the update of the shared variable with the local variable needs to be protected.
- If a shared variable is initialized, this should be done before threads are started. In this case, shared variables do not need to be protected.
static variables could be victims of data races, as they are only fully initialized at program runtime.(static)
thread_local guarantees that each thread that uses this variable receives its own copy of it.(Thread-local data)
atomic variables have major restrictions. Essentially, only integral data can be atomic. With C++20 this is still possible for floating point numbers. User-defined data can also be atomic if it is sufficiently simple.(atomic)
8. April 2025 at 16:58 in reply to: C.81: Use =delete when you want to disable default behavior – Use Case #63814723. March 2025 at 21:59 in reply to: Implement an asynchronous and interruptible iterative solver with concurrency #637975::Your data is probably on the same cache line. One cache line invalidates the other. More about cache lines: std::array and std::vector are your Friends.
23. March 2025 at 20:57 in reply to: Practice on STL sorting of strings comparing performance #637972::Performance tests without maximized optimization make no sense: https://godbolt.org/z/vjsdMxcKo. Additionally, you can sort in parallel.
::This is precisely how function template type deduction works (Template Arguments), which is called decay.
14. March 2025 at 12:00 in reply to: Missing Article Links in Week 3 – Lvalue and Rvalue References and Casts #637817 -
AuthorPosts