diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
commit | c44379cc7d9c7aa113989237ab0f56db12aa5219 (patch) | |
tree | 66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h | |
parent | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff) | |
download | ATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz |
Repo restructuring
Diffstat (limited to 'ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h')
-rw-r--r-- | ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h b/ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h new file mode 100644 index 00000000000..589d5710e47 --- /dev/null +++ b/ACE/apps/JAWS3/jaws3/Cached_Allocator_T.h @@ -0,0 +1,107 @@ +/* -*- c++ -*- */ +// $Id$ + +#ifndef JAWS_CACHED_ALLOCATOR_T_H +#define JAWS_CACHED_ALLOCATOR_T_H + +#include "ace/ACE.h" +#include "ace/Synch.h" +#include "ace/Malloc.h" +#include "ace/Free_List.h" + +#define JAWS_DEFAULT_ALLOCATOR_CHUNKS 10 +#define JAWS_CACHED_ALLOCATOR(T) \ + JAWS_Cached_Allocator< T, ACE_SYNCH_NULL_MUTEX > + +template <class T, class ACE_LOCK> +class JAWS_Cached_Allocator : public ACE_New_Allocator +// = TITLE +// Create a cached memory pool with <n_chunks> chunks each with +// sizeof (<TYPE>) size. +// +// = DESCRIPTION +// This class enables caching of dynamically allocated, +// fixed-sized classes. +{ +public: + + JAWS_Cached_Allocator (size_t n_chunks = JAWS_DEFAULT_ALLOCATOR_CHUNKS); + + ~JAWS_Cached_Allocator (void); + + void* malloc (size_t); + // get a chunk of memory from free store. + + void free (void *); + // return a chunk of memory back to free store. + +protected: + + char * get_next_pool (char *pool); + + void set_next_pool (char *pool, char *next_pool); + + void extend_pool (void); + +private: + + size_t pool_size_; + + char *pool_head_; + // Head of memory pool. + + char *pool_tail_; + // Tail of memory pool. + + ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<T>, ACE_LOCK> free_list_; + // Maintain a cached memory free list. + +}; + + + +template <class T> +class JAWS_TSS_Cached_Allocator : public ACE_New_Allocator +// = TITLE +// Create a thread specific cached memory pool with <n_chunks> +// chunks each with sizeof (<TYPE>) size. +// +// = DESCRIPTION +// This class enables caching of dynamically allocated, +// fixed-sized classes. +{ +public: + + JAWS_TSS_Cached_Allocator (size_t n_chunks = JAWS_DEFAULT_ALLOCATOR_CHUNKS); + + ~JAWS_TSS_Cached_Allocator (void); + + void * malloc (size_t); + // get a chunk of memory from free store. + + void free (void *); + // return a chunk of memory back to free store. + +protected: + + JAWS_Cached_Allocator<T, ACE_SYNCH_NULL_MUTEX> * ts_allocator (void); + +private: + + size_t n_chunks_; + + ACE_TSS_TYPE (JAWS_CACHED_ALLOCATOR(T)) ts_allocator_; + +}; + + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "jaws3/Cached_Allocator_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Cached_Allocator_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + + +#endif /* JAWS_CACHED_ALLOCATOR_T_H */ |