Resource Cache

Started by
0 comments, last by nife87 15 years, 9 months ago
I am building a very simple resource cache/manager. One of the most basic requirements of such a setup is to know how much memory a given resource consumes. That's my problem. If I create a texture in say, OpenGL using glTexImage2D, the GL implementation allocates a nice chunk of system memory to store the texture. Of course, I never know how much, nor when it will be returned to the system. The same could be said of OpenGL display lists as well. So the question is, how do people generally create resource management functionality that accurately reflects how much memory any given resource is using given the problem above?
Advertisement
Maybe I don't understand your question right, but... do you really need to know the size?

I only ever care about the size of something when I load it from disk (or when it comes from the network). Obviously I have to know, to allocate memory for it.
However, as soon as I'm handing something to OpenGL, it becomes a GLuint token from my point of view. It's no longer important what its format is, where it is, and how big it is. It's not my job to worry what to upload to the card and when, and how much memory it will take, the driver does that.

Thing is, as long as you still need a buffer/texture/whatever to render the next frame, it doesn't matter anyway. If you need it, you need it, no matter how big it is. What's important is when you don't need something any more, because then it can be discarded in favour to something else.
For the time being, I only keep track of memory allocated in RAM for resources, since you cannot ever trust the graphics driver to do things in some ordinary way which you may calculate the size of your loaded resources with.
This also perfectly fits my needs, since I can keep track of resource and memory allocations in RAM, the amount of textures/VBO's/PBO's/etc. loaded in graphics memory, and since I trust the driver to optimize the graphics memory management (with a couple of helpful advices from my side, of course).

This topic is closed to new replies.

Advertisement