Loading in memory a data array

This is a discussion on Loading in memory a data array within the C Programming forums, part of the General Programming Boards category; Hello, I registered here to ask for some help about a small problem that I don't know how to solve. ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    4

    Unhappy Loading in memory a data array

    Hello, I registered here to ask for some help about a small problem that I don't know how to solve.

    I am making a videogame in C. As you know, videogames requieres a lot of data like pictures and sound that needs to be loaded in the application. Actually, what I am doing is reading the bitmaps or wavs directly from disk, but this requires a real lot of extra files. Furthermore, those files could be stolen by anyone or easily replaced, something I am not interested in.

    So, my idea was to include all this data inside the compiled file. For now an executable for windows, but for porting reasons, it must not be windows' dependant.

    My solution to this is to autogenerate a header file containing all the data as an array of bytes for each file, so, instead of loading the bitmap from disk, I ask a function to retrieve the data of the desired "file".

    The problem is that I don't really know how to do this properly. My idea is to have a generator application that reads the required files and dumps the data into a .h file like:

    char tilesetPictureData [0][]= "56fm32... ";
    char tilesetPictureData [1][]= "56fm32... ";
    ...



    Then, import this header in the main application and then have another function:

    char* retrieve_tileset(int tileset)

    That returns me back the chunk of data of the desired object.

    This method could make that the whole data is included in the final executable, but probably it will be included in memory too, and that's not something I can afford. At the loading of each level in game I should free the data from the previous tileset and load the new tileset data.

    I need to know how can I make a data array that is not loaded in memory when the application runs, and how to retrieve that data without having the whole data arrays loading at once.

    Thank you very much and sorry if I didn't explain correctly. I will answer any question.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    You can make a zip archive, password-protected perhaps, and use something like zlib to access its contents. Your archive doesn't have to be compressed( to avoid the extra overhead ).
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    4
    That's probably not an option. For doing that I would encode my own files. But it would still need external files, and furthermore, to use them I will have to extract them to some kind of temorary folder. This still has the risk of material being stolen or hacked, and the loading times of the game would for sure increase exponentially, having to load the compressed file, uncompress the data and read the extracted data again.

    Thanks anyway

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    Well, there's no other way of doing that, except if you want to store your files encrypted in memory and dynamically decrypting them each time they are needed. But that would increase the lag exponentially too. So, you have do decide protection vs speed ...

    EDIT: And about your "freeing the tileset" problem, yes you can load the data independently, you only need to know a little about databases. And, for maximum protection, you could even wipe the memory where your data stood with zeros or something.
    Last edited by GReaper; 06-10-2012 at 04:06 PM.
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    4
    Thanks for the help, but I am sure it's possible to do. I know that the homebrew for nintendo DS works like that. You generate some header with all the information. But I don't have the sources so I don't really know how that process is done.

  6. #6
    Registered User
    Join Date
    Jun 2012
    Posts
    4
    Thanks for the help, but I am sure it's possible to do. I know that the homebrew for nintendo DS works like that. You generate some header with all the information. But I don't have the sources so I don't really know how that process is done.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Did you think about someone taking a screenshot of your game while running?

    How about taking a picture (with a camera) of the screen while the game is running?

    There is no way to show someone something and not have them be able to save it for themselves. The movie industry has been trying to do this for ages... and just go on piratebay to search for name of any movie to see how well that's working for them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading data into a dynamic array
    By serge in forum C++ Programming
    Replies: 9
    Last Post: 06-18-2009, 03:36 PM
  2. Loading process from memory
    By X PaYnE X in forum Windows Programming
    Replies: 15
    Last Post: 05-03-2009, 04:34 PM
  3. Loading a PE file into memory?
    By jsithy in forum Windows Programming
    Replies: 5
    Last Post: 12-29-2008, 10:58 AM
  4. Loading files into memory
    By アストラル in forum C++ Programming
    Replies: 22
    Last Post: 09-20-2008, 04:49 PM
  5. Help with loading data.
    By meeloff in forum C++ Programming
    Replies: 2
    Last Post: 11-04-2004, 09:00 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21