Easy communication between threads? I present you the 𝗗𝗮𝘁𝗮 𝗼𝗿𝗶𝗲𝗻𝘁𝗲𝗱 𝗰𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 𝗳𝗼𝗿 𝗺𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱 𝘀𝗶𝗻𝗴𝗹𝗲-𝗽𝗿𝗼𝗱𝘂𝗰𝗲𝗿-𝘀𝗶𝗻𝗴𝗹𝗲-𝗰𝗼𝗻𝘀𝘂𝗺𝗲𝗿 𝗰𝗼𝗺𝗺𝘂𝗻𝗶𝗰𝗮𝘁𝗶𝗼𝗻. The pattern can be implemented in all low level languages from C, modern C++, Rust, Zig, using templates, unions, polymorphism or std::variant, type erasure etc... Every problem requires a different specific solution, thus a different implementation. My version compared to the standard 𝗖𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 with virtual functions, it eliminates the overhead of the 𝗩𝗧𝗮𝗯𝗹𝗲 𝗱𝗶𝘀𝗽𝗮𝘁𝗰𝗵, where if the vtable is not already in cache you hit a 𝗰𝗮𝗰𝗵𝗲 𝗺𝗶𝘀𝘀, losing many precious clock cycles, (bad for RTOS or real time renderers). This pattern is perfect to pair with a 𝗹𝗼𝗰𝗸-𝗳𝗿𝗲𝗲 𝗿𝗶𝗻𝗴 𝗯𝘂𝗳𝗳𝗲𝗿 or 𝗾𝘂𝗲𝘂𝗲, one way communication between threads, The command pattern AFAIK is also heavily used in Job/Task systems. I've personally used it in my 𝗩𝘂𝗹𝗸𝗮𝗻 𝗿𝗲𝗻𝗱𝗲𝗿𝗲𝗿 on a dedicated thread, no locks, no mutex, no race conditions, it makes the coding experience easier. Of course there are also drawbacks compared, more boiler plate code, or heavy use of templates to make it more generalized, make a struct for each new command type, etc... It helped me gain 𝗮𝘁 𝗹𝗲𝗮𝘀𝘁 𝟱𝟬𝟬𝗳𝗽𝘀 to switch to another thread without too much hassle. If you think about it, if we could move the ownership of everything from a thread to another one, would this make multithreading easier to write? Save this post and give it a try! #programming #coding #C++
Stanislav Kirichenko’s Post
More Relevant Posts
-
The 𝗰𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 is useful 𝗳𝗼𝗿 𝗺𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱 𝗰𝗼𝗺𝗺𝘂𝗻𝗶𝗰𝗮𝘁𝗶𝗼𝗻 and more. This version of the 𝗖𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 uses 𝘀𝘁𝗱::𝘃𝗮𝗿𝗶𝗮𝗻𝘁 for a more elegant and modern approach, decoupling the command data from it's execution logic. The pattern has many variants, including templates, unions, polymorphism or std::variant, type erasure etc... Every problem requires a different specific solution, thus a different implementation. This pattern is perfect to pair with a 𝗹𝗼𝗰𝗸-𝗳𝗿𝗲𝗲 𝗿𝗶𝗻𝗴 𝗯𝘂𝗳𝗳𝗲𝗿 or 𝗾𝘂𝗲𝘂𝗲, one way communication between threads, The command pattern AFAIK is also heavily used in Job/Task systems. If you think about it, if we could move the ownership of everything from a thread to another one, would this make multithreading easier to write? Save this post and give it a try! #programming #coding #C++
To view or add a comment, sign in
-
I ran 10,000 iterations in a loop to see how different string concatenation methods perform—and the results were shocking! Using BenchmarkDotNet, I compared string +, StringBuilder, interpolation, and string.Concat across 10,000 loop iterations. Results: 🔵 Small concatenations: string + wins – simple operations, compiler optimized. 🔵 Large loops: StringBuilder wins – mutable buffer avoids repeated copying. 🔵 Loop interpolation & string.Concat: extremely slow and memory-hungry → ~379 MB allocated! 😱 Takeaways: 1️⃣ string + is fine for small operations. 2️⃣ Always use StringBuilder in large loops. 3️⃣ Monitoring memory and GC is critical when performance matters. 🖥️ My terminal output shows Mean, Memory allocations, and Gen0 counts clearly. #CSharp #DotNet #Performance #CodingTips #Programming #Developer #SoftwareEngineering #Optimization #Benchmarking #TechTips #MemoryManagement #StringBuilder #CodingPerformance #DotNetCore #LearnCSharp
To view or add a comment, sign in
-
-
💡 𝗖#/.𝐍𝐄𝐓 𝐂𝐥𝐞𝐚𝐧 𝐂𝐨𝐝𝐞 𝐓𝐢𝐩 🔥 💎𝗪𝗵𝗮𝘁 𝗶𝘀 𝗣𝗿𝗼𝗽𝗲𝗿𝘁𝘆 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴? Property Pattern Matching allows you to test whether an object's properties or fields match specific values without verbose null checks and nested conditions. It transforms complex if-else chains into clean, declarative expressions that clearly communicate your intent. ✅ 𝗞𝗲𝘆 𝗔𝗱𝘃𝗮𝗻𝘁𝗮𝗴𝗲𝘀 ◾ 𝗖𝗼𝗻𝗰𝗶𝘀𝗲𝗻𝗲𝘀𝘀: Reduces 5-6 lines of traditional null checks into a single readable expression. ◾ 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝘃𝗲𝗻𝗲𝘀𝘀: Enables nested property matching and complex conditions in a natural, readable syntax. ◾ 𝗧𝘆𝗽𝗲 𝗦𝗮𝗳𝗲𝘁𝘆: Compile-time validation catches errors early and eliminates runtime type mismatches. 🤔 Which one do you prefer? #csharp #dotnet #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
💡 𝗖#/.𝐍𝐄𝐓 𝐂𝐥𝐞𝐚𝐧 𝐂𝐨𝐝𝐞 𝐓𝐢𝐩 🔥 💎𝗪𝗵𝗮𝘁 𝗶𝘀 𝗣𝗿𝗼𝗽𝗲𝗿𝘁𝘆 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴? Property Pattern Matching allows you to test whether an object's properties or fields match specific values without verbose null checks and nested conditions. It transforms complex if-else chains into clean, declarative expressions that clearly communicate your intent. ✅ 𝗞𝗲𝘆 𝗔𝗱𝘃𝗮𝗻𝘁𝗮𝗴𝗲𝘀 ◾ 𝗖𝗼𝗻𝗰𝗶𝘀𝗲𝗻𝗲𝘀𝘀: Reduces 5-6 lines of traditional null checks into a single readable expression. ◾ 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝘃𝗲𝗻𝗲𝘀𝘀: Enables nested property matching and complex conditions in a natural, readable syntax. ◾ 𝗧𝘆𝗽𝗲 𝗦𝗮𝗳𝗲𝘁𝘆: Compile-time validation catches errors early and eliminates runtime type mismatches. 🤔 Which one do you prefer? #csharp #dotnet #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
📘 Problem Solving Update – Today’s Practice Had a productive session solving two solid problems focused on sliding window and dynamic programming. ✅ GFG POTD – Substrings with K Distinct Characters Approach: Used the classic “at most K” sliding window technique. The idea is to count substrings with at most K distinct characters and subtract substrings with at most (K−1) distinct characters. This converts the problem into an efficient linear-time solution using two pointers and a frequency tracker, instead of brute force. Key learnings: Two pointer window expansion and contraction Frequency tracking for distinct characters Turning an “exactly K” problem into a difference of two simpler problems ✅ LeetCode Daily – Minimum ASCII Delete Sum for Two Strings Approach: Solved using Dynamic Programming with Space Optimization. The goal is to make both strings equal by deleting characters with minimum ASCII cost. Defined DP states based on suffixes of the strings, where each state represents the minimum cost needed from that point onward. Optimized from 2D DP to 1D using only previous and current rows. Key learnings: DP on strings Transition based on character match vs delete choices Space optimization without losing clarity Consistent practice, deeper understanding. On to the next one 🚀 #ProblemSolving #DSA #LeetCode #GeeksForGeeks
To view or add a comment, sign in
-
I’m happy to share this Lexical Analyser project I worked on Emertxe Information Technologies!!!! 🚀 Project: Lexical Analyzer (C Programming) 🔍 Built an intermediate-level Lexical Analyzer that scans a C source file and breaks it down into meaningful tokens like keywords, identifiers, operators, and symbols. 💡 This project simulates the first phase of a compiler, focusing on: 1)Efficient tokenization of source code 2)Handling file I/O operations and string manipulation 3)Detecting and managing lexical errors during analysis ⚙️ Tech Stack: C Programming | File Pointers | String Operations | Compiler Design Concepts 🎯 Goal: Transform raw code into a structured token stream ready for the next stage of compilation. #CProgramming #CompilerDesign #LexicalAnalyzer #CodingProjects #Programming #SoftwareDevelopment Check it out here: https://lnkd.in/gw2Vt9-J
To view or add a comment, sign in
-
💡 𝐂#/.𝐍𝐄𝐓 𝐓𝐢𝐩 - 𝗗𝗲𝗰𝗹𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 🔥 💎 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗶𝘁? Declaration patterns let you check the runtime type of an expression AND declare a new variable in one step. When the pattern matches, the variable is automatically assigned with the converted result. This eliminates the need for separate type checking and casting. ✅ 𝗞𝗲𝘆 𝗕𝗲𝗻𝗲𝗳𝗶𝘁𝘀 ◾ Combines type checking and variable declaration in a single, readable expression. ◾ Eliminates explicit casting and reduces boilerplate code. ◾ Prevents type mismatch errors with compile-time safety. ⚡ 𝗖𝗼𝗺𝗺𝗼𝗻 𝗨𝘀𝗲 𝗖𝗮𝘀𝗲𝘀 ◾ Type checking in if statements: if (obj is string text). ◾ Switch expressions with pattern matching. ◾ Processing collections with different element types. 🤔 Do you use declaration patterns in your code? #csharp #dotnet #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
📌 Understanding the Core Components of C++ STL This diagram clearly shows how the Standard Template Library (STL) is built on three powerful pillars: 🔹 Containers – Store and organize data efficiently Examples: vector, list, map, stack, queue 🔹 Algorithms – Perform operations on data Sorting, searching, and manipulating data with optimized logic 🔹 Iterators – Bridge between containers and algorithms They help in navigating and traversing data smoothly 💡 When these three components work together, STL allows us to write cleaner, faster, and more efficient C++ code. #Cplusplus #STL #DSA #DataStructures #Programming #CodingLife #DeveloperJourney #ComputerScience #LearningInPublic #StudentsOfLinkedIn
To view or add a comment, sign in
-
-
The 𝗰𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 is useful 𝗳𝗼𝗿 𝗺𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱 𝗰𝗼𝗺𝗺𝘂𝗻𝗶𝗰𝗮𝘁𝗶𝗼𝗻. The pattern has many variants, including templates, unions, polymorphism or std::variant, type erasure etc... Every problem requires a different specific solution, thus a different implementation. This version of the 𝗖𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 with virtual functions, simplest form to implement. This pattern is perfect to pair with a 𝗹𝗼𝗰𝗸-𝗳𝗿𝗲𝗲 𝗿𝗶𝗻𝗴 𝗯𝘂𝗳𝗳𝗲𝗿 or 𝗾𝘂𝗲𝘂𝗲, one way communication between threads, The command pattern AFAIK is also heavily used in Job/Task systems. If you think about it, if we could move the ownership of everything from a thread to another one, would this make multithreading easier to write? Save this post and give it a try! #programming #coding #C++
To view or add a comment, sign in
-
#PEAK_System has released PCAN-Explorer 7, the latest evolution of its professional Windows software for monitoring, analyzing and simulating CAN, CAN FD and now full CAN XL networks. With support for higher bit rates and larger payloads, flexible licensing options and modern automation features like Python scripting, this update equips engineers with a next-generation toolset for automotive, industrial and embedded bus analysis. #PCANExplorer7 #CANXL #Automotive #IndustrialNetworks #EmbeddedSoftware #Connectivity #ElectronicsBuzz #powerelectronics #powermanagement #powersemiconductor https://lnkd.in/gUxZY92j
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Full source code here: https://github.com/WildFoxStudio/DODCommandPattern