1 //------------------------------------------------------------------------------
4 // Desc: DirectShow base classes - efines a non-MFC generic cache class.
6 // Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
7 //------------------------------------------------------------------------------
10 /* This class implements a simple cache. A cache object is instantiated
11 with the number of items it is to hold. An item is a pointer to an
12 object derived from CBaseObject (helps reduce memory leaks). The cache
13 can then have objects added to it and removed from it. The cache size
14 is fixed at construction time and may therefore run out or be flooded.
15 If it runs out it returns a NULL pointer, if it fills up it also returns
16 a NULL pointer instead of a pointer to the object just inserted */
18 /* Making these classes inherit from CBaseObject does nothing for their
19 functionality but it allows us to check there are no memory leaks */
21 /* WARNING Be very careful when using this class, what it lets you do is
22 store and retrieve objects so that you can minimise object creation
23 which in turns improves efficiency. However the object you store is
24 exactly the same as the object you get back which means that it short
25 circuits the constructor initialisation phase. This means any class
26 variables the object has (eg pointers) are highly likely to be invalid.
27 Therefore ensure you reinitialise the object before using it again */
34 class CCache
: CBaseObject
{
36 /* Make copy constructor and assignment operator inaccessible */
38 CCache(const CCache
&refCache
);
39 CCache
&operator=(const CCache
&refCache
);
43 /* These are initialised in the constructor. The first variable points to
44 an array of pointers, each of which points to a CBaseObject derived
45 object. The m_iCacheSize is the static fixed size for the cache and the
46 m_iUsed defines the number of places filled with objects at any time.
47 We fill the array of pointers from the start (ie m_ppObjects[0] first)
48 and then only add and remove objects from the end position, so in this
49 respect the array of object pointers should be treated as a stack */
51 CBaseObject
**m_ppObjects
;
52 const INT m_iCacheSize
;
57 CCache(TCHAR
*pName
,INT iItems
);
60 /* Add an item to the cache */
61 CBaseObject
*AddToCache(CBaseObject
*pObject
);
63 /* Remove an item from the cache */
64 CBaseObject
*RemoveFromCache();
66 /* Delete all the objects held in the cache */
69 /* Return the cache size which is set during construction */
70 INT
GetCacheSize(void) const {return m_iCacheSize
;};
73 #endif /* __CACHE__ */