I need to be able to load, use, and free resources from a single monolithic object. I have two requirements: 1. That the resource loaded is owned by the object that created it and 2. All objects in a "frame" (where a certain set of resources are required at a given time) can be freed at once, rather than the individual resources.

However, the "frame" system I'm talking about could be implemented, from what I see, in two different ways. I can't give much code examples due to the size of them but let me explain further:

  1. Pointers. By asking the "engine" (the monolithic instance for loading and storing resources) to create a "frame" and return a pointer to the instance. The "frame" pointer would have an interface to load certain resources into memory and hold them for use. Then, at a later time you can call a function to ask the "engine" to release the frame instance by passing it back the pointer (and it would any subsequent resource that was loaded in the "frame" or caching for later re-use).

It would look like:

IResourceFrame *frame = engine.openFrame(); //Create a frame and return a pointer to an interface
const Resource *resource = frame->loadResource(); //Load the resource from the frame
//Use resource
engine->closeFrame(frame); //Deletes frame and all of it's resources (or caches them)
  1. IDs. By asking the "engine" for an ID, then calling any function in the engine to load and use whatever resources you want with the ID as the first argument, then when you're done call a function passing the ID telling the "engine" it can release whatever resources that were associated with that ID.

It would look like:

int frameid = engine.openFrame(); //Create a frame and return an ID
const Resource *resource = engine.loadResource(frameid); //Load a resource from the engine using the id
//Use resource
engine.closeFrame(frameid); //Deletes frame and all of it's resources (or caches them)

The reason why this is needed in the first place is to move certain resources away from specific objects and into just one, but I'm trying to simply come up with an elegant interface for this. Any input is appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.