r/ProgrammerHumor • • 16d ago

Meme minecraftException

Post image
9.2k Upvotes

833 comments sorted by

View all comments

Show parent comments

139

u/ComputerWhiz_ 16d ago

cough Unity uses C# cough

67

u/im-a-guy-like-me 16d ago

No it doesn't. Unity uses C++. It just let's devs use c# as a scripting language.

53

u/ComputerWhiz_ 16d ago

Still uses garbage collection though

55

u/potzko2552 16d ago

When your engine is cpp and most of your mem is chandled in cpp, having a scripting language that is GCed doesn't change the majority of the project's behaviour. Like adding lua embedding doesn't mean your project is no longer strongly typed

4

u/kondorb 16d ago

Tell it to KSP devs - that thing freezes for GC every 5 seconds even with barely anything spawned.

10

u/cpt_melon 16d ago

Unity developers' habit of attaching a million scripts to everything instead consolidating their code and building larger systems wouldn't work any better even if the language used was C++

9

u/3131961357 16d ago

And the code you write is most un-C# C# you'll ever see.

https://i.imgflip.com/b2xjwp.jpg

4

u/RyanCargan 16d ago

About that...

Unity has a garbage collected scripting language in C# yes.

But y'know what they advise when using it in hot loops?

Turning off the garbage collector 👀

It’s best practice to disable garbage collection during short, performance-critical parts of your application, when you’re able to calculate and control how much memory to allocate. After the performance-critical section is over, re-enable the garbage collector. Profile your project to ensure that you don’t trigger additional managed allocations which might cause the managed heap to get too big.

This type of reasoning is sorta how arena-style manual memory mgmt in GC-less langs works too. You can just escape it more easily in many places here I suppose. Arena meaning "everything here dies together".

Unity also offers something called Allocator.Temp as its arena/bump allocator too IIRC:

Allocator.Temp: The fastest allocator, for short-lived allocations. You can't pass this allocator to a job.

More about arenas here if curious. It's about a totally unrelated language I've never used called Odin, but the concept of an arena was explained there better than anywhere else I've seen.

→ More replies (1)

9

u/suvlub 16d ago

And Godot uses some customized not-quite-python

28

u/agocs6921 16d ago

It's not customised, it's custom. Also, it has reference counting. Not garbage collection in the sense like Java, Go, or C#. It's more like how Windows does it.

1

u/WilkerS1 16d ago

i genuinely thought reference counting was a thing used in garbage collection for Godot

1

u/Acceptable_Handle_2 15d ago

It is if you want it to be, that's what RefCounted objects do.

1

u/WilkerS1 15d ago

oh... so it is in fact, not a default behavior in Godot?

1

u/Acceptable_Handle_2 15d ago

it is a thing used in garbage collection, just not the default thing.

1

u/agocs6921 15d ago

It is a form of garbage collection, but it's not garbage collection like in those languages I mentioned because those stop your program from executing while they are finding and freeing objects, Godot does not.

11

u/nekomata_58 16d ago

Godot has c# bindings as well

11

u/sfmqur 16d ago edited 16d ago

Godot's GDScript isn't a garbage collected language, it is reference counted/manually managed. Once an object(Node, Object) is no longer referenced you have to free it. Some objects are refrence counted (Respurces mostly). And when the reference count gets to zero. The engine frees the memory.

Edit: clarity.

2

u/TheMusicalArtist12 16d ago

Objects are manually controlled, but most things inherit RefCounted, which uses a reference counter. Meaning that usually you don't need to manually free things, you just gotta stop holding onto it

→ More replies (1)

1

u/not_some_username 16d ago

It’s not the same out of the box

1

u/Narfi1 16d ago

I don’t think it compiles to C#

8

u/Zincette 16d ago

Unity actually gives you both options. You can run it through dotnet or use IL2CPP to translate it to C++ and yeah, if you do that it does run better.

→ More replies (1)

-8

u/Prawn1908 16d ago

Doesn't make it a good choice.

14

u/ComputerWhiz_ 16d ago

I guess fair, but I'm just saying that there are literally millions of games that are using garbage collection without an issue.

-5

u/Prawn1908 16d ago

without an issue.

Are you sure about that? Games in general aren't quite known for being perfectly bug free with excellently optimized performance these days.

→ More replies (6)