xref: /haiku/headers/os/support/BlockCache.h (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 //******************************************************************************
2 //
3 // File:			BlockCache.h
4 //
5 // Description:		Manages a cache of same size blocks of memory
6 //
7 // Copyright (c) 2002 Massimiliano Origgi
8 //
9 // License:
10 //
11 //******************************************************************************
12 
13 #ifndef _BLOCK_CACHE_H
14 #define _BLOCK_CACHE_H
15 
16 #include <BeBuild.h>
17 #include <Locker.h>
18 
19 // Allocation type
20 enum
21 {
22 	B_OBJECT_CACHE = 0,
23 	B_MALLOC_CACHE = 1
24 };
25 
26 
27 class BBlockCache
28 {
29 public:
30 
31 					BBlockCache(size_t CacheSize, size_t BlockSize,	uint32 Type);
32 virtual				~BBlockCache(void);
33 
34 		void		*Get(size_t BlockSize);
35 		void		Save(void *Data, size_t BlockSize);
36 
37 private:
38 
39 virtual	void		_ReservedBlockCache1();
40 virtual	void		_ReservedBlockCache2();
41 
42 					BBlockCache(const BBlockCache &);
43 		BBlockCache	&operator=(const BBlockCache &);
44 
45 		size_t		fCacheSize;
46 		size_t		fBlockSize;
47 		void		*fCache;
48 		size_t			fMark;
49 		BLocker		fLock;
50 		void		*(*fAlloc)(size_t Size);
51 		void		(*fFree)(void *Data);
52 
53 		uint32		_reserved[2];
54 };
55 
56 #endif
57