Arenas, strings and Scuffed Templates in C

preview_player
Показать описание
A video made to highlight some strategies and tips for making using C easier

Relevant Links:

Arenas:

My Data Structure Implementations:
(Completely standalone if you remove the stabletable section)

Metaprogramming article by ryan fleury:

#MadeWithMotionCanvas
Рекомендации по теме
Комментарии
Автор

Some days, I just don't feel like writing code. Then a video like this pops up in my feed and I find myself back at the keyboard, refactoring something. Haha ... thanks for the C content!

WarrenMarshallBiz
Автор

This is the second time that you’re making a video about exactly the same thing I’m working on. Thanks again for the videos, super helpful!

yogxoth
Автор

Great video!

For me, the fact that you need to make everything yourself in C is fun : )

garklein
Автор

I don't write C any more (and never did any heavy lifting with it), but it's nice to see how development is evolving. I've always liked how much space C gives us to do things our own way (including how to screw things up royally, but I don't see the latter happening here!) I'll definitely give this another view. I'm in awe of the folks who really know how to do this stuff. C is still my favorite language; I never learned to hate it, even though I've had my share of awful bugs just like everyone else, but not as awful as the ones we get when we really know how to code. Now we've learned all about robustness. Cheers!

danieljulian
Автор

Lovely video. Your points completely explain why I switched to zig for nearly all of my performance critical code.

Nikoline_The_Great
Автор

You gained a sub. I use a couple of these tricks in my projects (except the arena allocator), and find them very useful. Thanks for documenting such neat tricks.

rohandvivedi
Автор

I have done, templates in C using macros. It's not pretty. Some of the reasons why are: confusing error messages, the fact that your code linter will have trouble telling you were errors are, junp to function definition will likely be broken, your code will be less readable, confusing formatting. That was the reason i ultimately switched to D.

VictorRodriguez-zpdo
Автор

Nice concise explanation of bump arena allocators.
I have a feeling you like Zig haha.
Also the explanation of how to use the pre processor to make templates is good.
I just wish there were a way to do that without using the pre processor or meta programming, but oh well

brecoldyls
Автор

Thank you SO MUCH, this is amazing and so helpful!! Arenas in special feel genuinely life-changing to learn about, thank you so much

kellybmackenzie
Автор

Thank you! I am a CS PhD student and I definitely learned something new: arenas/bump allocator with this video.
Arenas feel pretty useful to correctly free memory when raising exceptions during the function lifespan. We do not need to remember all the stuff we have to free when quitting the function early on.
I like to code in the Nim language, for its templates and meta programming features which are well easier to debug (and much more powerful).
There are plenty of features that I wish were there in C (default values, some automatic type inference for function callbacks, etc...) but the amount of optimisations in Clang/GCC, the reliability of debugging tools like Valgrind, the structural typing and the simplicity of the language (no absurd edge cases to learn like in JS) makes it an incredible language ;)

dimitrilesnoff
Автор

This video explains the ideas very clearly, thanks

mie
Автор

Really nice video! Got This In My Recommendation.

segsfault
Автор

Thank you man - this was super helpful for me

willisplummer
Автор

Great video mate, videos like these keep my spark up, thanks for this ❤

vinugb
Автор

The lack of templates is really what's dragging c down, and it's the main reason I use c++, only for the templates though, not for the OOP stuff. Great video! Arena allocators are wonderful.

hkejhkm
Автор

Nice, I am just now starting to lay out the basics of a c style compiled language I'm planning to implement. I was looking around what allocation strategies to support but couldn't decide.
In the past it was pretty easy either you garbage collect or use a malloc free system but nowadays there are so many niche competitors trying to revolutionize the game.
Thanks to this video I might consider making arenas my primary allocation strategy.

We will see ourselves again in 5 years when the language is mature enough to even work 😂

redcrafterlppa
Автор

FUCKING DELICIOUS VIDEO! JUST LOVE C

THANK U, KEEP DOING IT

opsJson_
Автор

For jank templates I prefer the header file variation where you #define an argument (usually the type but any template parameter) for the template and include the template header. The template header uses the template arg to generate a bunch of functions and struct, then undefines all it's args. This way you can debug the code as you would normally because the function isn't created in a macro expansion.

slayerxyz
Автор

I have some questions about how to use that string struct.
1. How do you print a string that's not null-terminated?
2. How do you get the length of the string? strlen (but that won't work if it's not null-terminated)? I assume you don't manually count characters.

yogxoth
Автор

7:30
Count-based strings have their benefits, but they come with tradeoffs. You're trading a 1-byte null terminator for 4-8 bytes of size for each string reference. It's a balance of pros and cons.

heapninja