r/GraphicsProgramming • • Jan 18 '24

Not loving C++

How crippling it is for somebody in the field of graphics programming to not love C++? I'm learning C++ right now and really don't like the experience. I wonder how bad it would be for me if I stuck with a very basic subset of C++, closer to C than to modern C++. Does that disqualify me from getting a lot of jobs, even if I'm otherwise competent entry-level graphics programmer?

To put my question in more concrete terms: I'm currently writing a gltf loader (purely as an exercise). As a part of that, I need to parse JSON, so I'm writing a JSON parser as well. Now, I could write the JSON parser using all the modern c++ features, most notably unique_ptr, but passing those unique_ptrs creates a lot of accidential complexity. Notably, I'm constantly getting various compiler errors. I'm muddling through them, but I'm not sureI see the light at the end of the tunnel - C++ spec seems so large that I can see myself still fighting the language even 5 years from now, instead of having fun with it. Whereas, I could skip all that, and just allocate the elements of the Json object tree in a basic memory arena, load whatever I need from the Json into relevant buffers, and then just free the entire arena. That's super-simple memory management approach that is totally sufficient here (I'm not going to ever need to free arbitrary subtrees of the JSON tree), and is something that's advocated by Casey Muratori in his streams.

12 Upvotes

74 comments sorted by

2

u/trinde Jan 18 '24

but passing those unique_ptrs creates a lot of accidential complexity

Unique pointers are supposed to represent ownership of an object, they make code a lot easier to understand. You should generally not be passing the unique pointer itself. You should be passing the object as a raw pointer/reference and only moving the unique pointer if some other code needs to take ownership.

1

u/pytanko Jan 18 '24

In my simple JSON parser, the typical usage of pointers is that I create an object on heap in some method, which then returns pointer to that object to the caller method, which in turn is sticking that pointer into some larger data structure. I do it all with unique_ptr, but that generates quite a bit of needing the std::move(), or complains about calling deleted methods etc. Most annoying thing so far are probably unlocalized error messages from the compiler (MSVC), which don't even point to the correct file.

All in all, I'm still very new to C++, so in honesty (as some people suggested) I should bang my head against the wall some more, as that is likely to lead to progress.

52

u/llamajestic Jan 18 '24 edited Jan 18 '24

I can’t speak for everyone but I think it’s pretty clear that in the graphics programming world, most people don’t use a lot of modern C++ features.

Where I worked we almost never used the std, instead we used custom containers for pointers, or famous libraries that are slim and fast. From the std, the feature we use the most is std::move. We basically do C, but use the C++ feature we find « sane » and improving our lives.

One important thing though is to know about common pitfalls. We often see the same kind of errors especially regarding the memory model.

7

u/vvodzo Jan 18 '24

That’s refreshing to hear! I’ve been working on my engine for a long time as a hobby project and pretty much do this. I do use std stuff/containers for non critical pieces that just makes life easier but mostly it’s just structs and pools.

Can you elaborate on the common memory model errors you’ve seen?

7

u/llamajestic Jan 18 '24

An example of a classic error I often see is a dangling reference. Looks easy to spot on a simple example, but when a codebase is made out of view sometimes someone might return a view referencing a lifetime that ends after the current function call.

Other error: The copy constructor might be called and you didn’t realize it. You can in general mark the copy constructor of a container as deleted since it’s unlikely you want to use it, or at least that’s our case.

3

u/MidnightClubbed Jan 19 '24

I delete the copy constructor before writing anything else in a class.  Once you get used to doing that you’ll never hit issues with accidental copies. Very few classes need to be copyable and the compiler will complain in places where a copy (or more likely move) constructor is needed.

1

u/vvodzo Jan 18 '24

Ah right those make a lot of sense, thanks! Was thinking more along the lines of people inventing their own memory management tools.

Move semantics is something I’ve always found as lacking clarity in C++, it would be nice if moves vs copies were more readily visible out of the box.

3

u/TheMusicalArtist12 Jan 19 '24

References and std::move, along with like OOP I guess is pretty much what I get out of c++.

Stringstreams and vectors have their place from time to time...

2

u/[deleted] Jan 19 '24

There's the "c++ STL bad" crowd that proceeds to use half of it and then there's the "c++ STL bad" crowd that rewrites 3/4 of it, but much worse. 

WaveSTL (90s, RogueWave) and EASTL are literally the only times that ever went well. STLPort authors belong in a prison without sunlight for the rest of their days.

2

u/TheMusicalArtist12 Jan 19 '24

It's bad because it just feels clunky, imo. Like, there's a Tuple STL class and it's just, not as clean as Python, etc...

It's honestly probably just how the language is designed, ya know?

43

u/Rockclimber88 Jan 18 '24

C++ is not supposed to be loved. It's a cross you're supposed to carry to your end. Hence double "+" in the name. C++ is an abbreviation of "Cross, cross, cross"

14

u/[deleted] Jan 18 '24

Maybe I'm a masochist but I love C++ lol. Sometimes I write stuff in C++ even when something else is clearly the superior choice.

1

u/IkalaGaming Jan 18 '24

I’m writing a ray tracer in C++, and a game in Java. I keep running into issues where I think things like “I need an unsigned int” or “I could use a struct” but that’s not a thing in Java.

To be fair Java has a lot of things that are very nice, but C++ is a pretty good language if a bit crufty in places.

8

u/Rob_Haggis Jan 18 '24

It definitely makes me cross at times.

9

u/FlyoverEscapePlan Jan 18 '24

The best arguments for avoiding (some) C++ features are usually performance based (though sometimes we do base those arguments more on intuition and "old wisdom" than on actual modern measurements).

I think the best argument for using modern C++ features is that you're better off dealing with compilation-time errors than runtime errors. Any time I've found a way to use the C++ type system to catch a class of errors at compile time it's been more than worth it.

The other best argument for is RAII. If I never have to manually release a resource again it'll still be too soon.

0

u/Grand_Gap_3403 Jan 18 '24 edited Jan 19 '24

What errors are you catching that wouldn't have been caught by the compiler using a "non-modern" subset of C++ (i.e. no use of std)? Genuinely curious because I can't think of any situation where I've been "saved" by either approach

Edit: I get downvoted but nobody can actually explain? It was a genuine question (specifically the part "use the C++ type system to catch a class of errors at compile time"--my understanding is the type system is fundamental to the language regardless of 'modern' features or not?). The only aspects I can think of are avoiding reinterpret_casts's for manual containers

1

u/corysama Jan 19 '24

Being able to create undupable "Move Only" objects is one of my favorite features of C++11.

I never call new or delete anymore. unique_ptr, structs, containers 100%. shared_ptr can obviously be misused. But, it's great when you need to send a read-only object to consumers on multiple threads.

Move optimizations, guaranteed return value optimization and destructuring mean I never use out-by-reference anymore. Return by value all day. If I want to return multiple things, define a 1-off struct full of the things to return. If I want to return things optionally, or differently, std::optional/std::variant.

Variadic templates + parameter packs make for highly optimizable utility functions that are flexible without va_arg madness, pointer casting or recursive templates.

if constexpr deprecates SFINAE madness.

I write libraries for other people. All this and more make it much easier to write interfaces that are hard for my users to screw up.

5

u/parrin Jan 18 '24 edited Jan 18 '24

Just use the bits of C++ that makes sense to use based on what you’re creating. I’m a graphics programmer with just shy of 25 years of professional experience of C/C++ and I wouldn’t say I use much of all the new shit in C++.

I actually think it would be a disadvantage to show code using overtly complicated C++ to another senior developer.

1

u/MidnightClubbed Jan 19 '24

That senior developer is risking being unemployable if they don’t at least understand complicated C++ code.  Even if your company is happy with c++11 many codebases and libraries have moved on and embraced more recently language features (I’m not talking about std here, although having an understanding of what it provides can be useful for tooling etc)

9

u/SuperSathanas Jan 18 '24

The thing here is that regardless of what you're applying C++ toward, especially if we're talking professionally, in a work setting, you're going to have to get familiar with at least some of the tools provided in the standard library, understand the semantics of the language and get more hands on or be more considerate of the many of the small details that you don't care about in most any other language.

If you're getting errors using std::unique_ptr, then the ultimate reason for that error isn't unique to the std::unique_ptr. There's something going on there that applies other places, too. It's not like std::unique_ptr is doing anything under the hood that you couldn't implement yourself, meaning you can (and will) cause these same sorts of errors while use other tools provided by the standard library and while writing your own tools.

Then, there's the matter of that the tools provided by the standard library do serve useful purposes (mostly), and are valuable out in the field. So, you're going to run into them and you're going to need to know how to work with them. C++ is huge, and you'll never use all of it, but if you're going to be working with other people, there will be parts of if that you will be expected to know how to work with. Most any place that cares about the quality of code being produced will have guidelines regarding just what their approved subset of the language is.

Finally (I'm trying to get to the point so I can shut up), I think you, or anyone else, should expect to beat their head against the wall with C++ for good while when first coming to the language, regardless of your experience in other languages. It's just big with many freedoms and flexibility, but due to that freedom and flexibility, it's pretty well impossible for the standard to address every case in which you might break things or for the compiler to know what you're trying to do and stop you from shooting yourself in the foot.

Once you work with the language for a while though, watching for undefined behavior and remembering what you should do and are expected to do becomes automatic, and when delving into new areas or using new tools you tend to know what questions you should ask and what implementation details you need to look into before slapping down some code. I think it's most always going to be a more involved process than using any other language, again, simply because there's so much available to you, but it definitely starts to flow after a while, like with much anything else.

15

u/shebbbb Jan 18 '24

Just use subset style. Don't worry about smart pointers or modern. Like Happy Gilmore. Just tap it in.

15

u/vingt-2 Jan 18 '24

I'd argue that smart pointers are the most useful things to keep around, especially for graphics programming which is 90% managing resource allocations. You don't have to use the standard implementations, but the concept is very, very useful.

4

u/_theDaftDev_ Jan 19 '24

Worked on various AAA engine and the most terrible codebases I worked with where from unconditional advocates of smart pointers. Smart pointer for high level resource data type, why not. Smart pointers for managing the lifetime of low level rendering API types? This is why so many engines suck ass today

1

u/MidnightClubbed Jan 19 '24

I’ll send you all the random crashes, console out of heap memory, and memory fragmentation bugs ;)

11

u/legends2k Jan 18 '24 edited Jan 18 '24

You're in good company. Read about Orthodox C++, a subset of C++ preferred by a decent crowd of graphics and game programmers.

It doesn't use C++ features like exceptions, RTTI, std allocators, containers, etc. that get in the way of reaping good performance.

Personally I believe the creator's quote

Within C++, there is a much smaller and cleaner language struggling to get out.

— Stroustrup

As long as I use it I (mostly) know what I'm getting from the compiler. Yes, I like it TBH. It has its problems but which language doesn't.

4

u/gplusplus314 Jan 19 '24

I code in Orthodox C++, mainly because I’m working with a code base from the early 90s. But you know what? It aged well. I can wrap my head around it.

1

u/Solrax Jan 18 '24

Within C++, there is a much smaller and cleaner language struggling to get out

LOL, that's a very old quote - it's from "The Design and Evolution of C++" which was back when the language was much smaller and simpler (first edition was 1994). And I read it back in the day, it made understanding the language *as it was then* much clearer. These days it seems they are loading the language up with every feature any other language comes up with, even if it breaks backward compatibility (looking at you "auto") or creates impenetrable syntax. And multipage error messages from templates.

2

u/legends2k Jan 19 '24

I read it back then too, but I still believe it. I mean I'm not compelled to use every feature they introduce in recent versions or any version for that matter. I like a small subset of all of C++, so I continue to use it. I adopt some new features here and there if I feel it is clean enough and I could wrap my head around it e.g. using enum class (C++11) has its benefits and I can be sure of the size allocated for a particular enum so I use it. Likewise with some type trait introductions or static if which make writing simple templates simpler. While I'm not too thrilled by allocators and such.

2

u/Solrax Jan 19 '24

I still keep the old AT&T "The C++ Programmers Handbook" on my shelf. Less than 130 pages and it had all the essentials.

6

u/susosusosuso Jan 18 '24

Actually, some areas such as game programming prefer a closer to C approach.

3

u/waramped Jan 18 '24

Most places will have you take a programming test as part of the interview process, so you will have to be reasonably comfortable with C++ in order to move past that stage. That being said, I wouldn't expect an entry-level applicant to be an expert in any way, and you will be forced to learn it on the job anyhow. Just know the basics, be comfortable with concepts like inheritance, pointers/references, RAII, and basic templates.

2

u/RaymondTracing Jan 18 '24

it sounds like you are struggling with memory ownership rather than C++.

I would avoid writing something that already exists and just use a package manager for that (I recommend Conan)

Otherwise focus less on keeping it modern and more on it looking good (so no malloc s or new s)

Write stuff instead of looking at the spec (no one ever reads it)

Use std::move(x) on unique pointers to change ownership (but polymorphism can still be difficult, I'd suggest references at that point)

Compiler errors are good! It means it caught something you might have missed. Though I appreciate its frustrating for new people it's really a good part of the language!

2

u/Ssjrd Jan 19 '24

This maybe to high-level conceptually, but if you think of the problem your trying to solve as using computer hardware to solve it (wether it’s rendering, ML, etc) instead of software code, the C/C++ with all of its low level, shoot yourself in the foot, memory management makes the most intuitive sense. I didn’t enjoy using Java and other high level languages where I couldn’t intuitively gauge what the ASM would look like for a block of code, or exactly how multiple threads were accessing a resource, etc. These things that can lead you to error prone code, are also the ones that can give you tremendous performance/ algorithmic optimization if you really understand the underlying mechanisms.

2

u/Solrax Jan 19 '24 edited Jan 19 '24

Great point. Plus switching to the disassembly in the debugger can be extremely educational. Besides understanding what your source is really doing, it can also show how inefficient some innocent looking code can be. A simple looking line of code can explode into a huge amount of machine language, especially if templates are involved.

It can also help you to find subtle bugs that look fine in the high-level language, but when you see what the computer is *really* doing it is obvious. That happens less to me now though, since compilers and editors have gotten good enough to flag most errors at compile time or edit time respectively.

3

u/saddung Jan 18 '24

Even if you don't use all of C++'s features for a given project it is still useful to be able to read and understand such code.

unique_ptr is pretty basic, not sure what you are finding confusing?

1

u/keelanstuart Jan 18 '24

That's the great thing about C++ ... you can use as much, or as little, of it as you want to. Your reasons may be valid or it may just be a vibe.

Not all of "modern" C++ is bad though... reserving STL container memory is important, the same way alloc'ing in large chunks you would in C, for performance... but the containers themselves are ok. functional is quite nice, also... as are lambdas in general. Obviously classes are good for encapsulation... but I personally never use any of the "smart" pointer classes. Memory lifetime have never really been a problem for me... and I don't know why people think they are.

Anyway, bottom line: use what you want.

1

u/jtsiomb Jan 18 '24

The best feature of C++ is that you don't have to use the whole of C++. Unlike other languages, you can pick and choose a subset to use that makes sense to you and your project.

Also, most graphics-related codebases, especially in games, are usually "C with classes" plus a few convenient library stuff. And many codebases don't even use STL containers and re-write the data structures needed from scratch.

1

u/Solrax Jan 18 '24

I can sympathize, having done C++ for about 30 years and watching it get more and more complex (or as they call it, "modern"), and having used a bunch of newer languages since then, and now back to doing C++ again. **

But there is something I can advise - if you haven't, take a look at "Effective C++" by Scott Meyers. This book really helps you learn to use and think about C++ correctly. Look for the 3rd edition if you want to get better at the non-modern version, look for "Effective Modern C++" for more guidance on the modern features.

** however, I will confess to liking lambdas and am glad C++ has them now.

1

u/Revolutionalredstone Jan 18 '24

Smart pointers and deep inheritance hierarchies have stopped more innovation than they have supported.

In SOME extremely large complex projects they do make sense, but it is at that same point you will acknowledge that your code base has become a turtle sloth.

There are plenty of ways to use all the most advanced ideas in coding without ever needing to use this unwieldy tool or the other ;)

1

u/fleaspoon Jan 19 '24

do yo really need json? is better to avoid it, just make your own simple format

2

u/O_Schramm Jan 19 '24

Agree. If you are doing stuff on that lower lever either way, it is probably better to go with your own binary format. Don't bother with all the text/object parsing.

1

u/O_Schramm Jan 19 '24

C++ is overrated. Most graphics programming / low end engine jobs usually just care about you being competant enough to handle memory management, and a lot of studios older studios actually prefer "orthodox c++" either way, which is c++ without all the hocus pokus. Though, what is worth noting is in bigger productions with more well known engines ex "Frostbite, Snowdrop, Unreal, Crytek", they almost always use modern C++ as a higher level to get all new features, support all of the newest tech etc, so you might find it harder in those AAA studios. Hope it helps in any way :)

1

u/-sebadoh Jan 23 '24

Would you like some pointers in the right direction?

1

u/-sebadoh Jan 23 '24

Some* s1 = new Some(new RightDirection()); Some* s2 = new Some(new RightDirection());

-6

u/[deleted] Jan 18 '24

Unfortunately, due to technical reasons and backwards compatibly C++ is quite verbose. Try Rust out, it's similar to C++ but the compiler and LSP helps you catch common errors which C++ will quite happily let you do without even a warning.

9

u/pytanko Jan 18 '24

I'm guessing that going into Rust would almost completely obliterate my chances at getting a graphics job, though... At least for now.

9

u/pedersenk Jan 18 '24 edited Jan 18 '24

I wouldn't bother with Rust for now. There are currently no industry standard graphics APIs providing a Rust API, it is all C (which C++ can consume directly) so you will either be using a random binding or generating / maintaining your own.

C++ is a bit of a nasty language but ultimately the best that the industry can offer. Some of your dislike of it could be due to inexperience but also, the language *does* have some real ugly parts.

Your issue with unique_ptr is possibly due to unfamiliarity of the language. You shouldn't really be passing these around often. They generally dictate ownership (the data is controlled by the containing structure), when simply referring to them, a reference or raw pointer is fine.

Honestly, keep going with C++ for about a year, write some simple SDL games and I am sure some of its (admittedly often hidden) elegance will start to show.

5

u/IceSentry Jan 18 '24

That's just not true. Wgpu is used to implement webgpu in firefox and maintained by a mix of Mozilla employees and open source contributors. It is used by pretty much everyone doing graphics in rust. You'll definitely not be using random bindings.

It's also pretty debatable to claim that c++ is the best the industry has to offer. It's certainly the most used but I don't think it qualifies at the best of anything. It's popular for legacy reasons more than anything else.

While it is absolutely possible to have a graphics job using rust. I can certainly agree that it's a tiny minority of the job market and OP would indeed be better off to focus on c++.

-1

u/pedersenk Jan 18 '24 edited Jan 18 '24

That's just not true. Wgpu is used to implement webgpu in firefox and maintained by a mix of Mozilla employees and open source contributors

It is true. Regardless of what language webgpu is written in. Its standard API is C:

https://github.com/webgpu-native/webgpu-headers

Dawn for example would need Rust bindings to work with Rust. None of them need C bindings to work with C.

The Javascript (which most people are exposed to for WebGPU) simply calls into the C API. Especially important because JS <-> Rust interop is poor.

But WebGPU is a cross-platform graphics API that's an abstraction layer above native APIs like Vulkan, Metal, D3D12. Same with WebGL, I don't really care about abstraction libraries or thin/fat bindings. They come and go.

5

u/IceSentry Jan 18 '24

The not true part is using random bindings or maintaining your own.

0

u/[deleted] Jan 19 '24

I don't think he understands what he's talking about

5

u/exDM69 Jan 18 '24

No, not really. You can acquire graphics programming skills using whatever programming language.

The industry uses predominantly C++, so you'll need to be fluent with it. But that does not mean you have to exclusively use C++ in your projects.

I have been using Rust (and Vulkan) for my graphics programming projects for a couple of years now (after a few decades of C and C++), and I could not be happier about it. The language is good, the tools are good and there are quite nice libraries available. It's not without its problems either (slow debug build performance, compile times). There are also other languages that might be suitable for low level graphics programming (Zig is one example).

tl;dr: you'll probably need C++ skills for the industry but you can learn graphics programming with other languages as well.

2

u/[deleted] Jan 18 '24

I am doing the same thing. Learning graphics using rust, as it is a pleasant experience. When I am advanced enough I’ll go through the trouble of learning c++ and creating a fcouple of example projects in it

2

u/[deleted] Jan 18 '24

I'm glad to see yourself and people speak up about this. I did message the OP to advise them that u/pedersenk advice was bad.

I explained what say about C++ being predominant, but I also mention that with Rust's FFI bindings it makes absolutely no different which language you choose. I even pointed that Zig can be used as a drop in compiler for C and C++ code and has better FFI as the binding generation is build right into the build process.

u/pedersenk advice is extremely naive and sets the precedence that C++ is somehow superior because you can work with C libraries. Yet you can work with C code in Rust, Zig and Odin.

1

u/pedersenk Jan 18 '24

sets the precedence that C++ is somehow superior because you can work with C libraries. Yet you can work with C code in Rust, Zig and Odin.

... and Java and C# and VB and Perl and Python and Ruby and almost any language under the sun.

But it is a mess. C++ interop with C is superior. Plain and simple. You will realize that after a bit more experience outside of Rust.

1

u/[deleted] Jan 19 '24

I've been using C++ for over 20 years; I know exactly what I'm discussing here. I feel your just determined to misunderstand despite multiple people explaining to you, how your statement was misleading.

2

u/pedersenk Jan 19 '24 edited Jan 19 '24

I've been using C++ for over 20 years

Nonsense. You even stated in some of your other posts that "you don't use C++".

despite multiple people explaining to you, how your statement was misleading.

Of each I have provided a strong rebuttable to. If you don't understand them. The onus is on you... Or you could PM people telling them that someone else is wrong like a flipping weirdo.

Jog on weirdo. At least the bunch of downvotes on your first naive "use Rust" post has pushed your nonsense Rust suggestion to the bottom.

1

u/[deleted] Jan 19 '24

Oh okay

1

u/[deleted] Jan 19 '24

Rust is a cult. It's a cult without beer at gatherings, so you know it's the worst of cults. 

Haskellers have beer at least.

-8

u/[deleted] Jan 18 '24

Not really, or it would depend on the company. New projects are probably going to be started in Rust or similar language, because of the modern memory management and language facilities which C and C++ don't guarantee.

This certainly isn't to say learning C/C++ is obsolete. These languages are relevant and will remain this way for a long time.

However, more to the point Rust has what is called the Foreign Function Interface (FFI). I'm using the Vulkan library which is written in C and calling the C code inside my Rust code. By doing this I can take advantage of the safety features of Rust and it's fearless concurrency.

So, effectively I'm using the C code inside of Rust. Which enables me to wrap raw pointers inside a Box<T> which automatically frees the memory allocated when the Box<T> is dropped.

Don't get me wrong Rust does still involve thinking and understanding of what is going on. For example C strings are different to strings in Rust. In Rust you can call into_raw method on a CString type which passes ownership of the memory to the code, for example. And you must remember to call the from_raw method on the C code to bring theemory back into your application for deallocating.

The C string example is showing off the possibility that it is possible to create a memory leak still in Rust but the invariants are a lot more limited and usually explicit as they require a unsafe {} block around them. Drawing your attention to that code having some sort of invariant you must manage yourself.

It, might not be for you. Or it might not help you get where you want to be. I just thought I would mention at it, as technically since it can interface with C it's essentially similar to C++ although not a direct superset.

Other languages which again interface or allow you to call C code are Zig and Odin. But if you really want to stick with C++ try reading the books at the links below.

https://www.amazon.co.uk/dp/B0CBNWNKQS/?coliid=IYO6XR4L39A57&colid=13I8RNR9QMYKF&psc=0&ref_=cm_sw_r_apann_lstpd_GQ6E8GNF5F70FC033E68&language=en_US

https://www.amazon.co.uk/dp/B01HXLVFNY/?coliid=I23VML5VC09FHN&colid=13I8RNR9QMYKF&psc=0&ref_=cm_sw_r_apann_lstpd_GQ6E8GNF5F70FC033E68&language=en_US

-4

u/EiffelPower76 Jan 18 '24

Why not using Java ?

With LWJGL, you can do anything

0

u/[deleted] Jan 18 '24

[deleted]

3

u/obp5599 Jan 18 '24

They most definitely have c++ engineers, what are you even saying?

0

u/[deleted] Jan 18 '24

[removed] — view removed comment

3

u/MidnightClubbed Jan 19 '24

This is plain wrong.  What part of C++20 (or 23) is unoptimized?  Indeed the addition of consteval and  if constexpr have made it easier to remove unnecessary calculations.  The stl is generally well optimized for general use cases, but you don’t need to use the standard library in order to use modern c++.

1

u/corysama Jan 19 '24

Meanwhile, I've been writing C++ console game engines since the days of the PlayStation1. OK... the PS1 required a lot of assembly. But, the N64 was fine with 100% C++.

0

u/[deleted] Jan 18 '24

[deleted]

7

u/obp5599 Jan 18 '24

I would say this used to be more true, but not any more. Most containers in the stl can be tuned to be performant. Basically just avoid a few like unordered_map and shared_ptr.

1

u/snerp Jan 19 '24

Unordered map isn't even bad, it's even actually good on msvc

1

u/obp5599 Jan 19 '24

Did it get better? I remember it had huge cache issues

1

u/snerp Jan 19 '24

Yeah, it's still not amazing to iterate though obviously

1

u/obp5599 Jan 20 '24

Yeah I meant more for general inserting and lookups it used to be pretty bad

1

u/snerp Jan 20 '24

Yeah sorry that's where it improved for sure. Lookup especially did really well when I was benchmarking maps for my game engine, I ended up just using the std unordered map(at least on mvsc) for anything that's just lookups and inserts and my own iterate specialized map optimized for insert+iterate

1

u/scallywag_software Jan 18 '24

Valves Source2 engine's been leaked a bunch of times, you could read that. It's pretty straight-forward to read. UE is open-source, and probably has a pile of container classes, but the engine itself is pretty C++-y. IIRC DOOM3 source code is available online, released by id.

Can't think of any other good sources off the top of my head, but there are probably a bunch more. People love writing custom container implementations