Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Resource Loading manager. Onto memory or not?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 s.Mason   Members   -  Reputation: 110

Like
0Likes
Like

Posted 16 August 2012 - 02:36 PM

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

Sponsor:

#2 nox_pp   Members   -  Reputation: 491

Like
0Likes
Like

Posted 17 August 2012 - 06:28 AM

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


#3 s.Mason   Members   -  Reputation: 110

Like
0Likes
Like

Posted 17 August 2012 - 09:47 PM

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 Posted Image .




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS