2 #ifndef JAWS_CACHED_ALLOCATOR_T_H
3 #define JAWS_CACHED_ALLOCATOR_T_H
7 #include "ace/Malloc.h"
8 #include "ace/Free_List.h"
10 #define JAWS_DEFAULT_ALLOCATOR_CHUNKS 10
11 #define JAWS_CACHED_ALLOCATOR(T) \
12 JAWS_Cached_Allocator< T, ACE_SYNCH_NULL_MUTEX >
14 template <class T
, class ACE_LOCK
>
15 class JAWS_Cached_Allocator
: public ACE_New_Allocator
17 // Create a cached memory pool with <n_chunks> chunks each with
18 // sizeof (<TYPE>) size.
21 // This class enables caching of dynamically allocated,
22 // fixed-sized classes.
25 JAWS_Cached_Allocator (size_t n_chunks
= JAWS_DEFAULT_ALLOCATOR_CHUNKS
);
27 ~JAWS_Cached_Allocator ();
29 void* malloc (size_t);
30 // get a chunk of memory from free store.
33 // return a chunk of memory back to free store.
36 char * get_next_pool (char *pool
);
38 void set_next_pool (char *pool
, char *next_pool
);
46 // Head of memory pool.
49 // Tail of memory pool.
51 ACE_Locked_Free_List
<ACE_Cached_Mem_Pool_Node
<T
>, ACE_LOCK
> free_list_
;
52 // Maintain a cached memory free list.
57 class JAWS_TSS_Cached_Allocator
: public ACE_New_Allocator
59 // Create a thread specific cached memory pool with <n_chunks>
60 // chunks each with sizeof (<TYPE>) size.
63 // This class enables caching of dynamically allocated,
64 // fixed-sized classes.
67 JAWS_TSS_Cached_Allocator (size_t n_chunks
= JAWS_DEFAULT_ALLOCATOR_CHUNKS
);
69 ~JAWS_TSS_Cached_Allocator ();
71 void * malloc (size_t);
72 // get a chunk of memory from free store.
75 // return a chunk of memory back to free store.
78 JAWS_Cached_Allocator
<T
, ACE_SYNCH_NULL_MUTEX
> * ts_allocator ();
83 ACE_TSS_TYPE (JAWS_CACHED_ALLOCATOR(T
)) ts_allocator_
;
86 #include "jaws3/Cached_Allocator_T.cpp"
88 #endif /* JAWS_CACHED_ALLOCATOR_T_H */