4

Recently I found here how to embed my resource files inside the executable. There is also the xxd method. Given this new found toy, that I used at first to embed the text of GLSL shaders into my game, now I want to embed every resource file needed to the game.

For now I only have a few kb of 3-D mesh data, but before this number grows, I would like to know how much data is it feasible to embed inside the executable? If I put a couple of gigabytes of texture data inside it, would it be ok? What are the performance penalties of abusing this feature?

2
  • When is the last time you saw an application that deployed a multiple gigabyte executable? I prefer to store my textures and other resources in the database. Making a library that can manage resource pools and caching in conjunction with your opengl wrapper is also a better design.
    – AJG85
    May 27, 2011 at 15:33
  • microsoft and others regularly gives you that large executables for their installers.
    – Lyke
    May 27, 2011 at 15:51

1 Answer 1

0

The disadvantage to this resource allocation method is that all resources will be present in virtual memory for the entire duration of your application.

For example, if you have 10 levels in your game, using a more common file-based storage solution you would only load the data for whichever level you are going to play. By loading all the game data at runtime you are allocating more RAM than necessary. A solution which uses an optimally minimal amount of RAM would only load the resources it needs for the duration it needs them.

However, if you were to use a file-based storage solution for your resources and load them all at the start of execution your RAM usage would be the same as the statically allocated resource method.

Also, if your target machine is a simple game console that does not do multitasking then you are usually free to use the available resources in whatever means suits you the best. There is no requirement to "play nice" as there's typically only one game running at a time.

If you're dealing with a few megabytes on a modern system the penalty is negligible, but the performance penalty when you get into multiple gigabytes of data is that you will be creating an unnecessary strain on the available memory resources of the system.

edit: be sure to see points raised in the comments

4
  • 4
    In a demand-paged memory environment, you're not using the RAM until you actually try to access the resources. All you're giving up is address space, which is free until you hit the limit. The OS will gladly give back the RAM when you stop accessing it. May 27, 2011 at 15:41
  • 1
    To facilitate better paging of that data, you should make the data const so it will be placed in the read-only section of an executable though, which will page the content back to the executable, not the swap file (imagemagic in the link of the Op does not do this.). The issue is virtual memory though. If you embed 1Gb of data in a 32 bit executable, your program gets 1 Gb less virtual memory, which is a real issue if you anyway need to extract/parse that data.
    – Lyke
    May 27, 2011 at 15:54
  • does statically assigning values to allocated memory not count as access? I know that if I do 'int a[1000];" no memory is allocated until use, but the same is true for "int a[1000] = {1,2,3,...};"? The OS is just memory mapping the file segments to RAM and will allocate on demand?
    – gravitron
    May 27, 2011 at 15:56
  • 1
    @graviton, yes that array might be paged in on demand, at least if that array is global and const. Though, if it's not const, it'll might be allocated in the data segment, which might be initialized at runtime, thus the data gets paged in when the executable is loaded anyway.
    – Lyke
    May 27, 2011 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.