63
votes
How do C++ games handle memory allocation failure?
Same as all average programs: They don't.*
For most applications there is no customer expectation that they continue working once memory runs out. All games fall under these "most applications". ...
37
votes
Accepted
Mechanics to keep mobs and environment alive without using tons of memory?
First of all, are you sure you really need that? Have you calculated the memory footprint?
A small back-of-the-envelope calculation: A single mob and its state should fit into 100 byte of data. Let'...
30
votes
Accepted
How does GPU handle texture and VRAM?
GPU compressed texture formats like DXT / BC / ETC are specifically designed to be read directly from their compressed form. They don't need to be unpacked into a raw RGBA buffer.
The way this works ...
22
votes
How do C++ games handle memory allocation failure?
Typically this kind of scenario never happens.
Firstly, virtual memory on modern operating systems means that it's highly unlikely to happen in normal operation anyway; unless you have a runaway ...
21
votes
Accepted
How do I know if memory isn't being handled right?
Virtual memory is allocated from the OS in large chunks, when even a byte is left still in use in that large chunk it cannot be released back to the OS.
Allocation libraries in user-space also keep a ...
14
votes
Mechanics to keep mobs and environment alive without using tons of memory?
One way you could solve this problem is not actually storing state on disk, but just setting up your generation code to use a seed for the random number generator, so it generates the same thing for a ...
8
votes
How does GPU handle texture and VRAM?
Answers to your questions really depends on the platform. Generally BC formats are kept in compressed form in memory and decompression is done in flight by GPU texture units, but there are exceptions. ...
7
votes
Accepted
How to prevent memory hacks?
I've seen some folks suggest obfuscating your variables something like this:
...
4
votes
Accepted
Efficient Dynamic Memory Management
deleteBuffer will delete the buffer in WebGL (and OpenGL) but I'm just curious, is there any reason not to just reuse the same buffer just put new data in it? (eg. have a pool of buffers?)
4
votes
Is replacing a struct field in a class generating garbage using C#?
Simple Answer
This isn't properly precise, but it's "good enough" for most day-to-day work:
Value types like structs do not themselves create garbage collection overhead.
If you already have some ...
4
votes
Unreasonably large memory use with high-res screenshot script
Textures, RenderTextures, and Materials use memory outside of C#'s managed heap (including ...
4
votes
Mechanics to keep mobs and environment alive without using tons of memory?
Save it to the hard drive instead.
Saving large quantities of data in a non-volatile fashion is literally why hard drives were invented. If a player isn't interacting with it anymore, you won't need ...
4
votes
Accepted
How do open world game engines allocate memory?
Creating a seamless open world without loading bars is not an easy task. There are lots of small and large problems which need to be solved. This is not a beginners project!
The basic approach is ...
4
votes
Accepted
What is happening during queue_free() process?
Reproducing the error
I managed to reproduce this reliably. It happens when calling queue_free on a Node that has already been ...
4
votes
Accepted
I am testing the flyweight pattern on thousands of GameObjects but its not helping save memory. What am I doing wrong here?
When it comes to components referencing assets, then the engine is already using the "flyweight" pattern internally. When multiple SpriteRenderers render the same sprite asset, then they are ...
3
votes
Accepted
How can I make a custom memory allocation for classes with virtual methods?
Take a look at std::allocator_traits that will allow you to use your allocator and construct objects in allocated space.
If you don't want to use that you can use placement new: ...
3
votes
Static variable pre-declaration & memory heap expansion in Unity
Local variables are not added to the heap. They are pushed onto the stack and immediately popped off the stack when they leave scope, thus already avoiding the heap (and the sort of memory allocation ...
3
votes
Any advantage of having chunks with sizes by the power of two?
The main advantage of power-of-two sizes is that division by a power of 2 (on an integer) is just a bit shift, and modding is just a mask. Both of these operations are blazingly fast to do on gobs of ...
3
votes
Is replacing a struct field in a class generating garbage using C#?
No, that line will not have any impact on the garbage collector. You are right in that the struct lives within the block of heap memory allocated for the class; the garbage collector only cares about ...
3
votes
Accepted
Should you avoid memory allocation and deallocation while the game is running?
I interpret this as meaning that you should do all the necessary heap allocation while the game is booting up, and arrange it in object pools that you then manage when the game is running. Is this ...
3
votes
Accepted
Rotating a Unity Texture2D 90/180 degrees without using GetPixels32 or SetPixels32? (To avoid heap fragmentation)
Two tricks we can use to get the RotateImage method down to zero allocations (in steady state):
We'll use ...
2
votes
How do C++ games handle memory allocation failure?
Well, mainly, the same way we did it before exceptions existed - the old "check the return value approach". If an allocator doesn't use exceptions, it will usually return ...
2
votes
Accepted
Is replacing a struct field in a class generating garbage using C#?
No, inspecting disassembly, correct me if I am wrong, appears to construct it in-place(compiled by VS2015 compiler) - lea loading the address of the struct and <...
2
votes
Voxel Game - High Memory and CPU Usage
First of all, we can say with absolute confidence that the culprit is not your glfwSwapBuffers call.
On it's own SwapBuffers doesn't do much; what it does however do is take all of the GL commands ...
2
votes
Vulkan - preallocating chunks of memory and resource memory requirements
Or is it safe to assume that if it's a device local heap it will always be viable for device local resources?
If it were safe to assume that, Vulkan wouldn't have APIs that specifically allow you to ...
2
votes
Accepted
How do open world games handle efficiently enemy respawn?
When you need to persist the state of a chunk but you are running out of memory, consider persisting it to the hard drive. If your game has enough complexity and data to warrant it, you might want to ...
2
votes
Memory is not getting freed on Destroy()
1000 isn't enough. I have taken your scripts and modified them a bit and it's showing that everything is working correctly. Instantiating 1000 objects gives you less than 1 mb - if you have seen any ...
2
votes
Accepted
Let both clients know of complete game-state in turn-based game?
This is not safe.
As soon as you let client know something, consider the player knows it too. Even if the information is hidden from players view in GUI, it can be more or less easily extracted from ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory × 114memory-efficiency × 27
unity × 26
c++ × 26
opengl × 12
performance × 9
c# × 7
java × 6
optimization × 6
libgdx × 5
android × 5
textures × 5
architecture × 5
assets × 5
2d × 3
rendering × 3
sdl × 3
sdl2 × 3
godot × 3
data-structure × 3
image × 3
gpu × 3
vbo × 3
objects × 3
resource-management × 3