Jump to content
  • Advertisement
moeen k

Rust vs c++. can Rust Change the Future of Game making?

Recommended Posts

A rust hello world has 2.2mb, compared to 17k in C++. Now, ok C++ may have a lot of background in the os per se.

A D hello world has 1.1mb, and D is garbage collected. Though maybe not needed for a hello world ... 😑

Can rust change the future ? If only i knew the future ...

Edited by Green_Baron

Share this post


Link to post
Share on other sites
Advertisement
10 hours ago, Green_Baron said:

A rust hello world has 2.2mb, compared to 17k in C++. Now, ok C++ may have a lot of background in the os per se.

A D hello world has 1.1mb, and D is garbage collected. Though maybe not needed for a hello world ... 😑

Can rust change the future ? If only i knew the future ...

Nonsense (at least on Windows). I have built Rust applications using Win32 API and dynamically loading functions that used less than 200 kB. And a hello world is approximately the same size as in C++.

image.thumb.png.dae5e52009be57a2a6159f8926e1b9ca.png

image.thumb.png.6c50553a890fe8c09a49142f2fa5b51d.png

Edited by l0calh05t

Share this post


Link to post
Share on other sites

Ok, a lot of the 2.4m of the executable are stuffing.

But even stripped, it is still 215k to 14k which is a relaxed approximation 🙂

Edit: what i wanted to say (but i am not apsecialist) it seems to carry more runtime stuff with it than a C/C++ executable. But i am not a specialist, you guys may in the end all be right.

Edited by Green_Baron

Share this post


Link to post
Share on other sites

A lot of the "additional runtime stuff" is clean error checking and unicode support. Strip only helps because cargo builds with symbols, even in release mode (and Linux isn't quite up to the level of Windows wrt separate debug symbol support).

There is a (slightly out of date) github page that lists some approaches to reducing file size even further:

https://github.com/johnthagen/min-sized-rust

Share this post


Link to post
Share on other sites

Rust does not have a garbage collector. It has a borrow checker. This is what makes Rust more like C/C++/FORTRAN and less like C#, D, or Java. Rust is NOT MANAGED. This is why Rust can guarantee latencies. This is what makes Rust able to even consider touching C/C++ for "game engine" level code. The cost of memory management is fixed, and a large heap won't suddenly slow down your game.

Rust may have more overhead by statically linking more runtime support in a trivially-sized program, but that overhead isn't really material on a project of any real size. Look at the size of the version(s) of MSVCPRT.DLL you have to include in any real-size C++ program and the worry about overhead seems trivial 🙂 

Rust is also functional, with a strict type system, like ML or Haskell (but not as strict as Haskell, so more like ML.) You might not realize it from just reading the code. This is a designed-in feature -- the benefits of functional, statically typed, programming are vast, and the main reason it hasn't caught on is 1) people don't like the syntax of existing languages, and 2) previous languages have been garbage collected, and thus had all of those problems. It's amazing what adding something as insignificant as a few braces to the syntax will do to make people "like" a language...

Rust is also designed by people who understand BOTH what it takes to deliver a real project, AND by people who understand language design. Most popular languages have been designed by people who like delivering projects, but NOT by people who actually approach language design with a solid technical foundation. Golang, Python, PHP, Ruby, Jai, D, JavaScript, and many other similar languages are all designed by people who "can write code" and "can use an existing language," but not by people who "have a strong background in programming language design and type theory."

I wish Rust the absolutely best. I know several important projects written in Rust (including the HTTP/3 stack used to serve CloudFlare, and the Servo browser rendering engine, and the ripgrep super-fast searching program.) Mainly, I'm hoping it can deliver safer code with tighter guarantees and fewer foot-guns than C++.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!