- 67
- 200 716
Zen Sepiol
Germany
เข้าร่วมเมื่อ 5 ต.ค. 2021
Hi, I'm Zen Sepiol,
I'll talk about C++ and software development in general.
I love code and I love software. Especially the hidden part (backend) where all the magic happens. Stay if you are as interested in uncompromised performance and sustainable designs as I am. Not all software is web or scripts and at its core everything needs to be fast. So join me in discovering the world of C++.
All code related to this channel can be found on github (github.com/ZenSepiol/ZenSepiol)
I'll talk about C++ and software development in general.
I love code and I love software. Especially the hidden part (backend) where all the magic happens. Stay if you are as interested in uncompromised performance and sustainable designs as I am. Not all software is web or scripts and at its core everything needs to be fast. So join me in discovering the world of C++.
All code related to this channel can be found on github (github.com/ZenSepiol/ZenSepiol)
How to build Snake with C++ and Dear ImGui
In this video I show how to create Snake with C++ and Dear ImGui.
Tools that I use:
www.virtualbox.org/
kubuntu.org/
code.visualstudio.com/
llvm.org/
clang.org/
mesonbuild.com/index.html
In code:
github.com/renatoGarcia/icecream-cpp
github.com/ZenSepiol
github.com/ocornut/imgui
github.com/epezent/implot
Tools that I use:
www.virtualbox.org/
kubuntu.org/
code.visualstudio.com/
llvm.org/
clang.org/
mesonbuild.com/index.html
In code:
github.com/renatoGarcia/icecream-cpp
github.com/ZenSepiol
github.com/ocornut/imgui
github.com/epezent/implot
มุมมอง: 1 606
วีดีโอ
How C++23 made my Thread Pool twice as fast
มุมมอง 3.1Kปีที่แล้ว
In C 23 there are some cool new features. In this video I show how to use the move_only_function to get rid of some overhead, improve the code and make it faster. Github: github.com/ZenSepiol/Dear-ImGui-App-Framework Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/oc...
How to write Thread Pools in C++
มุมมอง 9Kปีที่แล้ว
In this tutorial I explain how thread pools work in C and how to implement them. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
How to use Googletest and Meson to build C++ tests
มุมมอง 1.3Kปีที่แล้ว
Googletest (gtest) is the most popular framework to test C code. In this video I show how to use gtest with the meson buildsystem. The left part of the thumbnail is created with DALL-E, an AI system by OpenAI. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol...
How to calculate long tasks in GUI code (C++, Dear ImGui)
มุมมอง 2.8Kปีที่แล้ว
This video shows how to calculate long tasks in a separate thread to avoid framerate drops in GUI code. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
I challenged ChatGPT to improve my code
มุมมอง 386ปีที่แล้ว
ChatGPT is currently a big hype. I challenge it to improve some code that I have recently written and I explain, what the advice is and if it is actually useful. The left part of the thumbnail is created with DALL-E, an AI system by OpenAI. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/ic...
Building Tictactoe with Dear ImGui: #3 The Game Logic
มุมมอง 790ปีที่แล้ว
In this video, I show how to build tictactoe. We focus on the game logic and implement the graphics with Dear ImGui. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
The Dark Side of C++ - Coercion by Template Member
มุมมอง 467ปีที่แล้ว
Sometimes in C it is useful to assign a template of a derived class to a template of a base class. In this video, I show how to do this by using the coercion by template member pattern. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgu...
How to build a Web Scraper for Stock Market Data with Dear ImGui and C++
มุมมอง 2.9Kปีที่แล้ว
This video uses C and Dear ImGui to built a web scraper fpr stock market data. The data is downloaded from yahoo finance via curl and afterwards parsed and shown in a ImPlot graph. 00:00 Intro 01:30 Curl based web scraper 12:02 CSV parser for stock data 20:08 GUI for Input 25:29 Candlestick chart for Dear ImGui Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ ...
The Dark Side of C++ - Empty Base Optimization
มุมมอง 942ปีที่แล้ว
Empty base optimization is a technique in C to save storage. In this video I show how it works and how to use it to make your code more efficient. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
The Dark Side of C++ - Checked Delete
มุมมอง 732ปีที่แล้ว
Checked delete is an C idiom that fails compilation if an incomplete type is deleted. In this tutorial, I explain how checked delete works and how to use it. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
The Dark Side of C++ - Copy-On-Write
มุมมอง 2.2Kปีที่แล้ว
Copy-On-Write or lazy copy is a technique in C to avoid unnecessary copies. In this viedo I show how to implement copy-on-write using shared pointers. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
The Dark Side of C++ - Base-from-Member Pattern
มุมมอง 982ปีที่แล้ว
This video shows the C pattern called Base-from-Member. Base-from-Member is useful to create encapsulation across inheritance chains. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github.com/epezent/implot
Setting up a GUI app in 5 minutes (Dear ImGui, Docker, Cpp)
มุมมอง 3Kปีที่แล้ว
I show how to setup a GUI app based on Dear ImGui and Cpp using Docker. The provided template contains the necessary Docker container with Dear ImGui, Catch2, ImPlot, the OpenGl 3 framework code and the instructions how to use it. Here is the link to the repository: github.com/ZenSepiol/Dockerized-Dear-ImGui 00:00 Setup of a GUI app 04:12 Technical Details Tools that I use: www.virtualbox.org/ ...
The Dark Side of C++ - Attorney Client Pattern
มุมมอง 2.3Kปีที่แล้ว
This video shows the attorney client pattern. It is used to abstract the implementation details of a class when it is necessary to expose a certain privat implementation detail. Tools that I use: www.virtualbox.org/ kubuntu.org/ code.visualstudio.com/ llvm.org/ clang.org/ mesonbuild.com/index.html In code: github.com/renatoGarcia/icecream-cpp github.com/ZenSepiol github.com/ocornut/imgui github...
Building a Sudoku Solver - But everytime it fails, 20% of the code is deleted
มุมมอง 2.1Kปีที่แล้ว
Building a Sudoku Solver - But everytime it fails, 20% of the code is deleted
The Dark Side of C++ - Exception safety and Scope Guards (Scope Exit)
มุมมอง 1.1Kปีที่แล้ว
The Dark Side of C - Exception safety and Scope Guards (Scope Exit)
The Dark Side of C++ - Non-Addressable Types
มุมมอง 1.1Kปีที่แล้ว
The Dark Side of C - Non-Addressable Types
Can I build Tetris from scratch in ONE session? (Uncut, Dear ImGui, C++)
มุมมอง 9972 ปีที่แล้ว
Can I build Tetris from scratch in ONE session? (Uncut, Dear ImGui, C )
Building Tictactoe with Dear ImGui: #2 The GUI
มุมมอง 1K2 ปีที่แล้ว
Building Tictactoe with Dear ImGui: #2 The GUI
ONE click / TWO files - Recording of Screen and Webcam in OBS
มุมมอง 3K2 ปีที่แล้ว
ONE click / TWO files - Recording of Screen and Webcam in OBS
How to write C++ unit tests with Catch2 and Meson
มุมมอง 10K2 ปีที่แล้ว
How to write C unit tests with Catch2 and Meson
Building Tic-tac-toe with Dear ImGui: #1 Mouse event callbacks
มุมมอง 2K2 ปีที่แล้ว
Building Tic-tac-toe with Dear ImGui: #1 Mouse event callbacks
Can I build a clock using Dear ImGui in under an hour?
มุมมอง 6K2 ปีที่แล้ว
Can I build a clock using Dear ImGui in under an hour?
Can a robot learn by itself how to clean my appartement? (C++ reinforcement learning)
มุมมอง 1.4K2 ปีที่แล้ว
Can a robot learn by itself how to clean my appartement? (C reinforcement learning)
C++ Tutorial: How to use CRTP to extend your classes
มุมมอง 2.4K2 ปีที่แล้ว
C Tutorial: How to use CRTP to extend your classes
How to use Dear ImGui to build a simple Gui-App Framework in C++
มุมมอง 49K2 ปีที่แล้ว
How to use Dear ImGui to build a simple Gui-App Framework in C
have you checked if the benchmark was correct? I mean on assembly level. Is it not possible that there is more about that on optimization level and it optimizes the calculation also out. That is also a great step, but different reason.
Great video
Starting from c++ 11 cow strings are forbidden. Standard string is faster and more MT friendly (move constructors) . Starting c++ 14 std::string has a small string optimization ! Starting from c++ 17 compiler can perform guaranteed copy elisions!! Dont use cow strings! Dont use cow atall its obsolete
why do people pronounce an acronym like GUI as gooey? That's like pronouncing 'the US' as 'the us' or ROI as roy
Prerequisites: Call Forwarding concept
Thank you so much for this! Very clear and quick tutorial :D
why is C++ so complicated?
I haven't tried yet.. but thanks.. this was what I was searching for.. and didn't know it was even possible.
2:52 possibly undefined behaviour/bug. You are calling queue.front() which returns a reference to the first element. Then you .pop() the first element and your func reference may become invalid.
Hey, great video! Can you please show the commands to run the test. Unfortunately the terminal is hidden behind you
Hey, great video! at the end you show how to run the test. WHAT ARE THE COMMANDS YOU TYPED??
Man you deserve so much more recognition, Please promote your channel via Instagram reels or other platforms.
Well, but it's really not polymorphic in the true sense of the word. Can't put different objects into vector and iterate over them whilst expecting polymorphism.
These days it's better to variant
@@glidersuzuki5572 depending on used stdlib it might run even worse than virtual.
if you want performance you go CUDA and ironically all you need are barriers and atomics, no thread pool, no semaphores, no conditional variables, no latches, no nothin. CUDA is stupid powerful and so much easier to program, if you can believe it.
yeah, I thought it was harder to program in CUDA but that's because I read articles and tutorials from people that don't know what they're doing.
@SillySussySally I love Cuda as well. But remember, not everything has a GPU.
@@ZenSepioltrue, but if you want performance, as a consumer, you go full gpu.
If the heavy computation is an opengl GPU render, how to deal with it ?
Another way to do this (which also works on Mac) is to use the "Source Record" plugin for OBS. This lets you create a seperate file name for each source file in your scene, so you can record any/all of them seperately (in addition to the usual entire scene recording). There is a nice tutorial on the "TroubleShoot" TH-cam channel called "Recording seperate sources at FULL QUALITY" that has a tutorial on this.
Thank for this :) The bat file was getting a bit stuck on the scene selection of the 2 but I can manually deal with that
got it! just needed to change --scene to --collection Thanks again
thanks for the effort
This is really useful thank you. Do you, or anyone else, know how to start the two instances recording on a Mac? I've got my two profiles and scenes for screen and webcam, both have the same hotkeys to start and stop recording. I can open two instances of OBS but the hotkeys only work for the instance that has focus.
Can‘t help with that, I don’t use Mac.
Very good explanation!
Thank u so much. Magnificent 🤩
Great tutorial. Thank you so much.
In C++ the base optimization struct is known as std::_Compressed_pair
your video helped me A LOT understand how does meson subfile system works. Thank you <3
I HAVE to try this. I've been using Action!4K to record webcam and mic separately from gameplay but if this is doable in OBS then I may finally have a viable workflow in Obs and things might just run a little tighter for once. And maybe just maybe the sources won't automatically change on me pre- or mid-recording. UGH. Anyways, thank you for this !
The Achilles heel of Dear ImGui is the font rendering. It's unacceptably bad. Subpixel rendering is an absolute must for any serious graphical UI.
Thank you!!
Thank you so much! Finally I know how to do it, thanks man!
Very misleading about constexpr. Your example will be fully evaluated at compile time with optimization enabled. And constexpr doesn't guarantee compile time evaluation, unless you use it within a const context (template argument evaluation), or declare the result variable as constexpr.
hey this is super interesting! I love how video is structured too.
ImGui + ?
The best explanation of this I've ever heard. Thank you!
no need to use bind: template <typename Fn> auto AddTask(Fn fn) { auto pTask = std::make_shared<std::packaged_task<decltype(fn())()>>(fn); auto f = pTask->get_future(); Add([pTask]() { (*pTask)(); }); return f; }
But then wouldn't you be fixated to no argument (I mean, return_type(void)) functions? I might be wrong, but how can we make it so we could actually send functions with arguments?
You do not need to use packaged_task, you can just pass a lambda to std::thread, std::thread thread([]() { // code here }));
spurious wake ups are not bugs, for example you can get a spurious wakeup when a laptop comes out of sleep mode, there is literally no other way to handle that without re-checking the condition
Thank you for the tutorial. This was very helpful and easy to follow. 👌
Hmm, is Godot considered a small project? This is what they use for their build system.
Godot Game Engine
I usually build double precision build of it and it takes roughly 5-10 minutes to build. and I have a beefy workstation (Ryzen 9 5950X) I honestly dont have anything to compare it to so I didnt have a problem with the build time.
What do you normally use for writing GUI applications? I tried wxWidgets but would like to try GTK because it has an editor (Glade/Cambalache). However, not sure what I need to install.. Meson, MSYS2, GTKMM vs GTK4 vs GTK3 etc. For example, I have Visual Studio Community do I still need MSYS2 (pacman -S mingw-w64-x86_64-toolchain base-devel etc) ? or can I just unzip the GTK source and build using VS? Do I need gvsbuild (Visual Studio Project or Meson Project) ? Also for testing , do you recommend CppUTest, google test , catch2, doctest, ??
For testing I use Catch2. For GUI apps either Dear ImGui or QT. I have a video for Dear Imgui which explains what packages you need.
Thanks it worked 👍
Worked perfect mate, congrats!
I'm reading a very large csv file (~500mb) and making a sweeping animated plot using ImPlot. This is really helpful to offload the csv parsing to a separate thread. Thanks! I have a question though, how is future_result.wait_for not blocking the GUI thread? Is it skipped over if the task is not yet complete and then re run at the next iteration of Update()?
Yes exactly. It is possible to specify a timeout, when the future will return. No timeout means it returns immediately in case the background job has not finished processing.
the most funny part is justification of replacing a single virtual call with templated trick.. - for performance! you saved maybe 2 CPU cycles. may the future generations remember your historical deed! :)))
It’s unnecessary, but fun. 😄
This actually doesn't work. It completely removes the point of a virtual function to begin with. The problem is that all the derived types will now have different base types. Usually, the point of a virtual function is so you can have an array of base type pointers, and by calling the virtual function from the base type pointer, each object "knows" its derived type and calls the corresponding function. Using the way he describes in this video, you can't make an array of base types, because each derived type has its own unique base type, so you have to make an array for each derived type, and if you have separate arrays for each type, you might as well make each array with its own derived type, so the concept of a virtual function becomes pointless. Using his example, you might as well make the template function take "(T* obj)" as a parameter instead of "(Base<T> *obj)". The CRTP technique CAN be used to speed up virtual functions a bit, but you have to add another non-template base class that your crtp class inherits from so that all the cinstances can be casted to the same type to make an array, and you have to create a function pointer as a member, and in the constructor of the derived class, you set that pointer equal to a static function defined in the derived class. This means that the runtime will not have to do a lookup to figure out which dervied class type to use, the object will have the function pointer as one of its own data members. There are a couple points to take into consideration for this method: - It will not be as fast as a non virtual function call, because of the fact that the location of the function is not known at compile time, so you have an indirection where the pointer needs to be accessed before the function is called, but since you are probably about to access other members of that object anyway, the value of the pointer is probably already cached (or was about to be cached) so it won't even add an additional RAM access, so it is super fast compared to doing a lookup for that function pointer by first accessing the virtual method table. - if you only have 1 or 2 virtual functions using this method, you will save ram over the standard virtual function scheme, because each object will have 1 extra pointer, and that would be the case with a virtual function as well, but since this method has no virtual function table, you save on RAM. However, each additional pseudo-virtual function you create in this way will add another pointer to every instance, while virtual functions will continue to only add a single pointer to each instance, so it could end up wasting a lot of RAM, so in that case, you are trading RAM for speed. - You have to be careful with the default assignment operator of the base class, because setting a base class instance equal to another will copy the pseudo virtual function pointer as well, and if you are setting a base type equal to a derived type casted to a base type, you will crash if you try to call this virtual method. So to deal with that, you need to explictly implement the assignment operator for your base class and set that pointer equal to the base class's version of the function, and to properly copy a dervied class, you have to use the standard "base *Dervied::Copy()" function, and you can use the pseudo-virtual scheme for that too. - Your pseudo virtual member functions will now be static functions, so you have to call them with the "this" pointer as the first member like you would have to do with C, so to call them, you have to do obj.PseudoVirtualFn(obj, otherParams), but you can get around this by using an intermediate function that does this for you automatically.
Thanks for the elaborate comment! Interfaces and base class pointers are one of the reasons for inheritance. But there are more reasons, e.g. less code, easier maintenance, clear structure, class extensions and quite some more.
@@ZenSepiol There are more reasons for inheritance, but there aren't more reasons for virtual functions. Virtual functions were created entirely to keep track of the inherited type from a base pointer. As you showed, you can completely get around virtual functions if you aren't working with base pointers.
omg, those eyes! Never seen anything like them.
👀
This maybe slowest possible thread pool ever
TL;DR - I'd look at the queue first, there should be 10-100x more action per second. Probably a mutex in there, not something wait- or lock free.
The real problems begin when you have 30-40 threads; when microbenchmarking they hit the queue too frequently and synchronizing the cache is beginning to be issue. Having N internal queues is also problematic since work stealing or any sort of work balancing will mean communication between threads (=cores) which is memory writing and root cause for the issues. TP + lots of cores + microbenchmarking = bad experience, but in the video's case 3 ms for 1000 tasks is at least 10-30x less than what it should be, that's why the queue is the suspect number one. If this is for "real" work it's roughly 350K tasks per second, if you use this for a game that could potentially run 120 fps that's still 2900 tasks per frame or so, but taking all CPU for one core for the orchestration which is unacceptable. Let's say 10% so ~ 300 tasks per frame, that should get a lot done but it's possible to bump that to 3000-20,000 tasks per frame if needed with some re-structuring of the code but even 1000 tasks sounds stupid amount and wasteful. IDK, it gets a bit muddy here what the use case is going to be but the current code should do alright as it is.
Did you measure? I just ran this on a (very limited) virtual machine, so obviously my numbers are quite low. The code itself should perform decently, but is not optimized for any specific usecase. The best thread pool implementation is heavily depending on the task itself, there are lots of options to optimize with different pros and cons.
idc about the views, this was some nice overview
thanks youu uwuw, i'll need to research templates futures and mutex stuff first & come back.. ;)) #godblessamerica #wtfisakilometar
how did you get the intellisense working in your python and scons files? For example `Environment` is underlined in red since the python intellisense thinks it's an undeclared variable
I don’t remember exactly. I probably just turned the squiggly lines of in those files.
Yon need to use a teleprompter :)
😅
Fantastic video. Hope to see a lot more video on ImGui!
Thanks! Time is tight but I still have some ideas 💡