|
List Info
Thread: Freeimage notes and avs cache expiration proposal
|
|
| Freeimage notes and avs cache
expiration proposal |

|
2007-05-25 19:05:26 |
|
First, about the new freeimage plugin.
Miranda related stuff is in Miranda folder only. Anything else shouldn9;t be touched to allow easy updates when freeimage releases a new version with bugfixes or improved features. In that case, it should be fairly easy to overwrite all the freeimage source files in order to stay up-to-date. Our own code shouldn9;t be affected at all.
Second, I've plans to implement cooperative cache expiration into avs.
Right now, avs has an internal timestamp for each avatar cache entry which is always updated when a plugin requests an avatar. However, avs cannot know whether plugin(s) still need the image or not. So there must be some way of cooperation between plugins using avs and avs itself.
The first method would be harder to implement. Whenever a plugin needs the picture (i.e. for drawing it), it must update the ace->t_lastAccess member with a valid time() value. The cache expiration would then only have to check the timestamp. But this is unsafe, because in some cases (
e.g. an inactive and minimized message window) a plugin would not update the timestamp and the cache may think it can expire the avatar, because its apparently no longer needed by any plugin (which would be wrong).
The other idea is an event which is fired when a picture is subject to be removed, because its t_lastAccess value is old enough. In that case, all plugins using avs *should* subscribe to the event and indicate whether they still need the picture or not.
e.g. for the message window it could look like:
HookEvent(ME_AV_EXPIREAVATAR, ExpireAvatar);
.... ....
// wParam == hContact // lParam = (DWORD *)
static int ExpireAvatar(WPARAM wParam, LPARAM lParam)
{ DWORD *stillNeeded = (DWORD *)lParam; HWND hwnd = WindowList_Find(hMessageWindowList, (HANDLE)wParam); if(stillNeeded) *stillNeeded = (hwnd == 0); //the window is open, so we still need the picture and set the value to 0
return(0); }
Similar code can be used by the contact list to indicate whether a contact is still on the list and its picture shouldn9;t be removed from the cache.
The expiration logic will set the value in *stillNeeded to 1 and keep the avatar when the value is 0 after the event completes. This must be done *reverse*, because not all plugins may subscribe to the event and those who don't will not have a chance to set it to 0 in any way.
Alternatively, we could use a return value of 1 in the event (not sure, if that could work though).
The expiration will be done in a very slowly running background thread - the thread will scan the cache every 10 or 20 minutes and do this slowly with reasonable delays and fire the event for each picture which has not been accessed for a while.
For larger contact lists, this should help to reduce memory and overall gdi usage, especially when Miranda has been running for longer periods of time. The expiration logic will only expire avatars which have been inactive for a while.
Alex (Nightwish)
|
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|