Resource Loading manager. Onto memory or not?

Started by
1 comment, last by s.Mason 11 years, 8 months ago
Since I don't mind reinventing the wheel for the sake of learning something I've been working on a small engine/framework as a foundation to work on some simple games. When I was working on my imageLoading manager (part of the resourceLoading bundle), at the moment I have it set up in a way that once a image is loaded, its temp. held (in memory) by the program as long as its running. If a call asks for an image that hasn't been loaded yet, it does so, else it returns the copy that was loaded and stored in a hashmap (which essentially is in memory).
I've also done pretty much the same for my audioResourceLoading manager.


Now what I'm thinking of implementing down the road is that the imageLoading manager only holds image files that are under a certain size or animations (other things like static backgrounds can be reloaded if needed).
And as for the audio, if its sound effects its pre-loaded onto a clip and therefore its held in memory. But for large audio files like background music, I'm thinking of maybe streaming it and buffering it so that its played as its loaded, with a sourceDataLine.

One thing I'm wondering is, I know when i load an image and an instance is presenting it on the screen (using it as representation), its being held in memory. Now if I'm putting a copy of it in a hashmap will that copy be in memory as well? or is it using the same memory space as the first one that was loaded? Same goes for when I create other instances that use this same image as a representation. Does anyone know?

And yes I know tools like Slick2D handle all this resource loading stuff for you (or so I've read), but I'm mostly doing it for the learning experience. For example to get that audioLoader going I learned a great deal of the sound API.
So yeah, just wanna hear some thoughts on this. ;D
Advertisement
If your resource loader is returning the images/audio from the hash map by reference, then your instance is using the SAME copy and taking up no additional memory (except the size of a pointer/reference.) However, for images, if you're rendering with hardware, then you are also necessarily holding a copy of the image in video memory.

Also, I go about my resource loading in a different way. I like to have a completely generic loading backend, when possible, that loads files from some source (generally the filesystem, but could be the network, or an archive) and puts them into memory as a blob. Then, I pass that blob off the particular subsystem to be decoded and whatnot. This way, you don't end up duplicating your file loading logic. Loading images, loading audio, loading models, etc. are all the same at the most basic level.

Between Scylla and Charybdis: First Look <-- The game I'm working on

Object-Oriented Programming Sucks <-- The kind of thing I say


If your resource loader is returning the images/audio from the hash map by reference, then your instance is using the SAME copy and taking up no additional memory (except the size of a pointer/reference.) However, for images, if you're rendering with hardware, then you are also necessarily holding a copy of the image in video memory.

Also, I go about my resource loading in a different way. I like to have a completely generic loading backend, when possible, that loads files from some source (generally the filesystem, but could be the network, or an archive) and puts them into memory as a blob. Then, I pass that blob off the particular subsystem to be decoded and whatnot. This way, you don't end up duplicating your file loading logic. Loading images, loading audio, loading models, etc. are all the same at the most basic level.


Great, thanks for resolving that inquiry of mine. And thanks for the tip there. I'll work on abstracting my file loading logic a bit more so that I could go at the same you do. Thanks smile.png .

This topic is closed to new replies.

Advertisement