Hot answers tagged memory-efficiency
102
"Memory" and "efficiency" are commonly misused terms, so I'll give you an answer for four different elements that may affect the performance of your game.
I will be oversimplifying way too many things to keep it short and concise, but there are tons of inaccuracies in this text below, so take it with a pinch of salt. However, the main concepts should be ...
39
Simple answer: the game is divided into chunks, while you move around chunks are constantly being loaded behind your back before you can see them and thrown away when you leave the area. To every simple answer is a complex solution that weighs innumerable trade-offs in implementation... but you get the idea.
For games where you think you can see tens or ...
39
the app crashes when it reaches 1.5Gb.
This strongly suggests that you're not representing your tiles correctly, as this would mean that each tile is ~80 bytes in size.
What you need to understand is that there needs to be a separation between the gameplay concept of a tile, and the visual tile that the user sees. These two concepts are not the same ...
36
Are you looping through all 500,000 tiles when you're rendering? If so, that's likely going to cause part of your problems. If you loop through half a million tiles when rendering, and half a million tiles when performing the 'update' ticks on them, then you're looping though a million tiles each frame.
Obviously, there's ways around this. You could ...
20
Split the terrain into regions or chunks. Then only load the chunks that are visible to the players and unload the ones that are not. You can think of it like a conveyor belt, where you're loading chunks at one end and unloading them at the other as the player moves along. Always staying ahead of the player.
You can also use tricks like instancing. Where if ...
19
In an average game, there are hundreds
or maybe thousands of obects in the
scene. Is it completely correct to
allocate memory for all objects,
includiding gun shots(bullets),
dynamically via default new()?
That really depends what you mean by "correct." If you take the term quite literally (and ignore any concept of correctness of the implied ...
17
Game Engine Architecture has some information regarding this topic. The basics are that you need to do some analysis to understand what your memory requirements per level/frame/etc. are like, but there are a few patterns the author mentions having seen several times:
Stack-based allocators: These allocate a large segment of memory once, and then allocate ...
16
Once an image is loaded off the disk and is formatted for rendering, it will use the same amount of memory regardless of whether that image was saved to disk using PNG, JPEG, or GIF.
General rule of thumb: JPEG is a lossy format, and will degrade image quality in order to make the image smaller on disk. PNG, on the other hand, is a lossless image format, ...
10
Previous answer pretty much nails it all. Also worth mentioning is Dungeon Siege I.
Here's a paper from one of the developer which actually goes over some of the architecture needed to make it work and common pitfalls:
http://www.floatingorigin.com/mirror/continuous-world.htm
I'd say it's a must read if you actually want to implement something like that.
10
Use your common memory management sense. Use pools/freelists for things that are frequently allocated and deallocated (i.e. particles), free memory blocks that aren't in use. However, don't try to preallocate large chunks of memory upfront. iOS doesn't guarantee memory nor does it swap, so any memory you have allocated is taking resources away from the ...
9
While I agree with the sentiment: "don't worry about it unless it's a proven issue", I do think it's worth thinking about early on: retro-fitting a solution is much more painful. And yes, only updating 'nearby' tiles is they way to go. But storage and addressability of items in your game world efficiently is very important for performance reasons.
What ...
8
You can do this in C#, but you'll likely need to P/Invoke a lot of the functionality you'd need. C or C++ is probably more well-suited to the task -- you'll have fewer hoops to jump through. There are a few open source "cheat engine" projects out there you can look at for a better idea of what you're going to have to do.
How do I find the correct memory
...
7
std::string does not do copy on write. CoW used to be an optimization, but as soon as multiple threads enter the picture it's beyond a pessimisation- it can slow the code by massive factors. It's so bad that the C++0x Standard actively bans it as an implementation strategy. Not just that, but the permissiveness of std::string with dishing out mutable ...
6
Swapping textures will kill your performance. Modern hardware has only gotten more susceptible to this problem, not less, as the speed and power of the shader units and video RAM are growing much faster than the speed increases of the bus between system RAM and the GPU.
The only sane approach is to cut down your texture sizes, or generate procedural ...
6
Technically "batching" is putting multiple actions and their data into one data structure so it all can be executed at once rather than invidualy.
The biggest bottleneck of modern GPUs is not their working power but the communication between your game running on the CPU and the GPU. Each package of data send to the GPU has a overhead, but the overhead of a ...
6
If anything, the first option might be better for cache misses since generally you'll be iterating through, say, all the Renderable components at once. Just copy the data you need into that component to avoid cache misses due to looking up data.
But it seems like you're suffering from design paralysis. Do you actually have a working game yet? Are the ...
5
In case you don't find such a comparison chart, the alternative is to inject an own allocator to the STL classes in question and add some logging.
The implementation I tested (VC 8.0) uses no memory allocation just by declaring a string/vector/deque, but for it does list and map. The string has a short string optimization, since adding 3 chars didn't ...
5
I don't have much to add to Josh's excellent answer, but I'll comment on this:
Should I create any memory pool for dynamic allocation, or is there no need to bother with this?
There is a middle ground between memory pools and calling new on each allocation. For example, you can allocate a set number of objects in an array, then set a flag on them to ...
4
The tree-as-array sounds like a win to me. Just do a depth-first traversal of your hierarchy and fill out an array; when rewinding through the recursion you can either update the parent with the absolute index to the child or just the delta-from-me, and the children can store the parent indices either way as well. Indeed, if you use relative offsets then ...
4
This is all highly theoretical but you may be able to use categories (Mac Developer Tips) to override NSObjects (Apple Developer) alloc and dealloc methods.
4
I've been wondering about this as well, so I decided to check out some popular games and watch Firefox's plugin container memory consumption.
Memory starts and defaults back to around 5-10MB on my setup. With that in mind, here are the peak memory usages in the first 3-5 minutes of gameplay for some popular games:
The Company of Myself - 35 MB
Don't Touch ...
4
FWIW, I was helping out a family member complaining of a slow PC. She plays CafeWorld on facebook. Investigation lead to Firefox/the flash plugin taking up almost a gigabyte of memory usage. I thought this might have been a fluke, having experienced many browser-based memory leaks over the years, closed everything and tried it with another browser. I watched ...
4
According to your tags it says "browser-based-games" depending on the game and its complexity, I would say 100mb most likely too much, unless you are creating a large mmo style flash game(even that is very large!)
There is a bunch of compression options you have for flash as well, which may shrink your game down
tiny: 0 - 200 KB;
small: 200 - 700 KB
...
4
The answer depends on your target audience. Do you want people to play your flash game on their Netbook and/or their flash supporting Playbook or Android tablet? If so, then memory usage over and beyond 50 MB is likely going to be an issue. If you only expect your game to be played on tricked out gaming rigs, then taking up 100-400 MB memory is likely not ...
4
Byte56's answer is good, and I started writing this as a comment to that but it got too long and contains some tips that might be more helpful in an answer.
The approach is absolutely just as good for server as it is for a client. In fact it's probably more appropriate, given that the server will be asked to care about far more areas than a client will. The ...
4
It's not a tightly-defined technical term. Batching is basically any system where you perform multiple operations as a set rather than individually, and often this is done because it's more efficient to do so. The efficiency gains usually come from being able to re-use some or all of the context that the operation requires.
So, sprite batching is just any ...
4
For fast software rendering, there are a few things you really want:
16-pixel scanline alignment, for SIMD or vectorized code.
32-bit RGBA or BGRA chunky (as opposed to planar) pixel formats, for fast 4-byte indexing. BGRA for fast copying to video memory for display, or RGBA because that's how image data is usually stored in files. If no alpha is needed, ...
4
1 kB = 1024 Bytes.
Most of programming languages have 1 Byte = 1 character, so:
If your lines are 1 character long, 1 kB = 1024 lines
If your lines are 1024 characters long, 1 kB = 1 line
If your lines are 25 characters long, 1 kB = about 40 lines
BTW. if your programming language is compiled, it has nothing to do with memory-efficiency.
BTW2: There ...
3
You seem to be worried about how to store your data when you should be concerned with the design of both your data, and how you expose it. Storing data in files or using a database is not a solution to design.
Instead of a singleton, pass the data by reference into functions. It may make sense to use a hierarchy of data types, such as a planet type that ...
3
There is practically no limit. As most things though, that is not 100% sure. What you are going to be limited by is hardware.
The default FPS is set to 30, but you can change it to 60 if you like. If you are not able to do all the work in your main Update Loop in one frame then you will start to see frames getting dropped. This is bad.
Also, there is a ...
Only top voted, non community-wiki answers of a minimum length are eligible
