Skip to main content
added 377 characters in body
Source Link
Komi Golov
  • 3.2k
  • 19
  • 29

If I'm understanding what you're doing correctly, it seems like the callers should get a shared_ptr to the bitmap, while the cache keeps a weak_ref. That way, bitmaps will only exist while you are using them, and the cache will know when a bitmap stops being used (the weak_ref becomes invalid). However, this does lead to the overhead of shared_ptr, which may be unacceptable in a game.

EDIT:

I'm not sure why you'd new and delete the map; however, you could make people Release() each individual bitmap, and the map would then check for that while cleaning. This will incur very little overhead (one bool, plus a check and occasional delete when searching).

In any case, just letting it be and never unloading bitmaps sounds like a very bad option.

If I'm understanding what you're doing correctly, it seems like the callers should get a shared_ptr to the bitmap, while the cache keeps a weak_ref. That way, bitmaps will only exist while you are using them, and the cache will know when a bitmap stops being used (the weak_ref becomes invalid). However, this does lead to the overhead of shared_ptr, which may be unacceptable in a game.

If I'm understanding what you're doing correctly, it seems like the callers should get a shared_ptr to the bitmap, while the cache keeps a weak_ref. That way, bitmaps will only exist while you are using them, and the cache will know when a bitmap stops being used (the weak_ref becomes invalid). However, this does lead to the overhead of shared_ptr, which may be unacceptable in a game.

EDIT:

I'm not sure why you'd new and delete the map; however, you could make people Release() each individual bitmap, and the map would then check for that while cleaning. This will incur very little overhead (one bool, plus a check and occasional delete when searching).

In any case, just letting it be and never unloading bitmaps sounds like a very bad option.

Source Link
Komi Golov
  • 3.2k
  • 19
  • 29

If I'm understanding what you're doing correctly, it seems like the callers should get a shared_ptr to the bitmap, while the cache keeps a weak_ref. That way, bitmaps will only exist while you are using them, and the cache will know when a bitmap stops being used (the weak_ref becomes invalid). However, this does lead to the overhead of shared_ptr, which may be unacceptable in a game.