News for hackers. Stuff that matters.
Re:The Poor Man's Voxel Engine by stcredzero on Thursday February 19, 2015 @05:01PM (#9077392)
Long story short, the garbage collector doesn't like to clean up large objects. I end up writing a custom "allocator" that hands out 3D arrays from a common pool. Later, I realize most of the arrays are 90% empty, so I break each chunk into 10x10x10 "sub-chunks" to further reduce memory pressure.

This episode is one of many which explain my present-day distaste for memory-managed languages in game development.

If you push any programming environment far enough, you will always end up "writing a buffer pool" or some other such memory management optimization task like this. So are memory-managed languages all just "bad?" No. That's way too simplistic. Memory-managed languages are just one particular set of tradeoffs. You can think of it as a kind of "technical debt." Is debt always bad? No. Sometimes it's the smart thing to do.

So where should the blame lie? Either on the person who chose the tool, or just chalk it up to the "unforeseeable" and switch to a better tool.

(And this is why building modular, well-factored systems is often the smart thing to do.)

(EDIT: It occurs to me that this story parallels the development of many industries. Things start out "hacky" and cobbled, but then standard interfaces are established so that components become "modular." Then, when people in that industry learn more about precisely what people need and what works best, modularization is left out to build a leaner and better performing widget. Yes, modularity is sometimes the smart move -- but like all things, it is very dependent on context!)

Re:The Poor Man's Voxel Engine by et1337 on Thursday February 19, 2015 @06:02PM (#9077773)
This comment is entirely too wise and reasonable for me to endorse. I need things in black and white. Garbage collection bad! Technical debt bad! Modularity good!
Re:The Poor Man's Voxel Engine by mlvljr on Friday February 20, 2015 @12:39AM (#9079118)
U lucky simple-minded bastard! :)
Re:The Poor Man's Voxel Engine by angersock on Friday February 20, 2015 @12:43AM (#9079134)
So, I will point out that in the case of frequent allocations and deallocations of small objects, most managed memory environments tend to have a bad time. This is forgivable but there will inevitably be GC pauses to clean up lots of internal fragmentation.

For game development, this is far more noticeable than in other applications, specially because there tend to be both lots of these allocations when doing vector arithmetic for graphics, physics and gameplay, and also because there is by definition a human being with 100% focus on what the program is doing and watching for any perceived choppiness.

For this reason, one of the first things to do when attempting game programming in these environments is to reach for a pooled math library.

Re:The Poor Man's Voxel Engine by pekk on Thursday February 19, 2015 @07:51PM (#9078261)
I think you're substantially agreeing with the author you've quoted, at least as far as the quote. Expressing distaste for memory-managed languages in game development and being able to cite a specific scenario for that is not the same as saying that memory-managed languages are all just bad. I think you, the author and anybody with a modicum of technical maturity can agree that "fast" memory-managed languages are not at an absolute global optimum because they make specific tradeoffs that not everyone will always want to make. Granting this, if we have even one reason to still keep around a memory-managed language (and that's not hard to come up with) then we have a case for keeping multiple languages around and being able to interface among them.

Not everybody realizes this; especially among people who argue about programming languages on web forums, there are still a large number who are still married to the idea that one language has to do everything and if any language has any weakness, we should leave it alone as "bad" because its flaws mean that it is not the Miss Universe of programming languages. It apparently takes some technical maturity to realize that significant flaws are often part of complete packages of tradeoffs that make something a great choice for some contexts even while they are not the best choice for some other context.

Re:The Poor Man's Voxel Engine by stcredzero on Thursday February 19, 2015 @08:05PM (#9078298)
I think you're substantially agreeing with the author you've quoted, at least as far as the quote.

Indeed. The sibling comment to yours is by him.

Re:The Poor Man's Voxel Engine by m_mueller on Thursday February 19, 2015 @08:29PM (#9078390)
Is there any cross platform language that does it like Objective C w/ ARC? I find that one a pretty good balance between being able to go nitty gritty with optimisations while not having to care about memory management details for the standard use cases. IMO it's also much easier to learn than C++. Could Rust be the answer?
Re:The Poor Man's Voxel Engine by yoklov on Thursday February 19, 2015 @09:43PM (#9078607)
C++ std::shared_ptr does the same thing as ARC (reference counting based on scope/lifetime). Rust probably has something similar in it's standard library.

FWIW I wouldn't use reference counting in game development if I could avoid it, because it has pretty bad performance characteristics as well (the only thing it really has over GC is that it's deterministic, and that, with the exception of in Objective C, you can choose where and where not to use it).

Re:The Poor Man's Voxel Engine by maccard on Friday February 20, 2015 @03:57AM (#9079595)
Most games don't do any heap allocations at al during runtime(or at least very very few), so you shouldn't/don't end up with garbage collector pauses during normal gameplay. If you refcount your main structures, they can be auto cleaned up /removed when changing levels/loading scenes/swapping chunks out on the fly.
Re:The Poor Man's Voxel Engine by anon4 on Friday February 20, 2015 @06:03AM (#9079916)
As an aside, it seems bizarre that you can exhaust the address space simply by allocating large objects over and over. Doesn't the windows vm system reclaim unmapped pages? Surely the .NET runtime uses holes in the Large Object Heap? It can't be that idiotic that new allocations always bump the pointer, right?