Thanks for the great videos! Totally agree on the design benefits of Options structs. I see this a lot in Golang. One additional consideration that you did not mention is whether to pass the struct by value or by reference. If the struct is large (say > 16 bytes) then you most likely want to pass by reference to avoid the memory copy penalty.
@MikeShah6 ай бұрын
Cheers, thanks for mentioning that! Indeed anything larger than the pointer size (8 bytes, so usually 16-bytes aligned) is worth by reference.
@polyontomorphic Жыл бұрын
Very useful to display that int main() { return 0; } Really cleared things up.
@MikeShah Жыл бұрын
😅
@NickEnchev7 ай бұрын
One thing of note about pImpl, especially in the given context of a game (or engine), is the fact that you guarantee indirection when accessing the implementation. In the case of a game, you'd be accessing many of these items per frame, potentially leading to very costly cache misses. I only bring this up since you example included a game character.
@MikeShah7 ай бұрын
Agreed -- that's a very good point! It'd be worth measuring to see how bad a penalty -- especially if that pointer is changing frequently, or the underlying data, then cache hits could really start to add up. So probably a reasonable pattern to use during development when ABI is unstable, but likely worth removing in a 1.0 release as things stabalize for performance.
@NickEnchev7 ай бұрын
@@MikeShah It actually makes a pretty big difference. If you look at the way Unity shifted to DOTS for example, away from a traditional OO approach, they moved to a cache friendly data oriented approach. The performance difference is actually quite massive as you process hundreds or thousands of game entities in your game loop, the data stays hot in your cpu cache, ready to be processed.
@MikeShah7 ай бұрын
@@NickEnchev The difference between where you're getting cache hits (i.e. which level, L1, L2, L3, or DRAM) indeed is an order of magnitude at each level. Indeed optimal design is likely something data-oriented where you have indices into flat, fixed-size arrays for your entities.
@ricardonunosr2 жыл бұрын
I know you said it would be a nice exercise to try and find this API design in real code. But if someone cant find it it would be nice to show 1 or 2 quick examples of real code on the video. Loving the short and useful videos keep it up
@MikeShah2 жыл бұрын
Cheers, you are right it would have been useful to show in some open source projects. Will keep that in mind for future :) Video later on on the importance of reading code is coming!
@damondouglas Жыл бұрын
In the context of templated classes, do you still use pimpl? Thank you for sharing these tips
@MikeShah Жыл бұрын
That's getting into interesting territory. 🙂 You could probably specialize a template or provide a template parameter to the implementation, but in all honesty I have almost always had concrete implementations. Do you have a use case you're thinking about using this?
@damondouglas Жыл бұрын
Thank you for responding. 🙂 I haven't a concrete use case. Yet I find a lot of what I code gravitates towards generics.
@MikeShah Жыл бұрын
@@damondouglas very cool 🙂
@joebosah27272 жыл бұрын
Very useful. Thank you very much. This video helped me fully comprehend Chapter 3.1 of Martin Reddy API for C++ Your course is very comprehensive for smallies like moi converting from Old C++ to Modern C++. Keep it up.
@MikeShah2 жыл бұрын
Cheers Joe!
@joebosah27272 жыл бұрын
@@MikeShah I love C++. It is no magic
@ghulam25452 жыл бұрын
One thing I would like to guess, having hands on experience with OOP could be considered as one of the prerequisite.
@MikeShah2 жыл бұрын
Agreed, this lesson is a bit forward looking. Probably not the way for everyone to write code, but for maintainers of libraries or code that a lot of folks will be dependent on for a long time. These two tips should be useful in that context. :)
@jaykraft9523 Жыл бұрын
hint: do these typing in an editor rather than writing, you lost me at the start
@MikeShah Жыл бұрын
👍 You're probably right -- I may do a follow-up in the future, as these are two API tips I like to use 🙂