summaryrefslogtreecommitdiff
path: root/ace/Malloc_T.h
diff options
context:
space:
mode:
authornw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-13 05:10:42 +0000
committernw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-13 05:10:42 +0000
commit63e99a0f37d40cf72fbc6e0123e0489f8d6cf790 (patch)
tree8739a610453c80368a53ce38dd96ae39340a3efc /ace/Malloc_T.h
parentcd3962290ff3c24020e0c461bc666ce39d20af74 (diff)
downloadATCD-63e99a0f37d40cf72fbc6e0123e0489f8d6cf790.tar.gz
Added ACE_Cached_Mem_Pool_Node_T and ACE_Cached_Allocator.
Diffstat (limited to 'ace/Malloc_T.h')
-rw-r--r--ace/Malloc_T.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/ace/Malloc_T.h b/ace/Malloc_T.h
index 432aa405145..f7718645a6c 100644
--- a/ace/Malloc_T.h
+++ b/ace/Malloc_T.h
@@ -20,6 +20,60 @@
#include "ace/ACE.h"
#include "ace/Synch.h"
#include "ace/Malloc.h"
+#include "ace/Free_List.h"
+
+template <class T>
+class ACE_Cached_Mem_Pool_Node_T
+ // = TITLE
+ // ACE_Cached_Mem_Pool_Node_T keeps unused memory within free
+ // list Free list structure is kept within the memory being kept.
+ // The length of a piece of unused memory must be greater than
+ // sizeof (void*). This makes sense because we'll waste even
+ // more memory if we keep them in a separate data structure.
+ // This class should really be placed within the next class
+ // ACE_Cached_Allocator. But, if you have read enough ACE
+ // code, you know why this can't be done.
+{
+public:
+ T *addr (void) { return &this->obj_; }
+ // return the address of free memory
+
+ ACE_Cached_Mem_Pool_Node_T<T> *get_next (void) { return this->next_; }
+ // get the next Mem_Pool_Node
+
+ void set_next (ACE_Cached_Mem_Pool_Node_T<T> * ptr) { this->next_ = ptr; }
+ // set the next Mem_Pool_Node
+
+private:
+ union
+ {
+ T obj_;
+ ACE_Cached_Mem_Pool_Node_T<T> *next_;
+ } ;
+};
+
+template <class T, class LOCK>
+class ACE_Cached_Allocator : public ACE_New_Allocator
+{
+public:
+ ACE_Cached_Allocator (size_t n_chunks);
+ // Create a cached memory poll with <n_chunks> chunks
+ // each with sizeof (TYPE) size.
+
+ ~ACE_Cached_Allocator (void);
+ // clear things up
+
+ void* malloc (size_t);
+ // get a chunk of memory
+
+ void free (void *);
+ // return a chunk of memory
+
+private:
+ T *pool_;
+
+ ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node_T<T>, LOCK> free_list_ (ACE_Locked_Free_List::ACE_PURE_FREE_LIST);
+};
template <class MALLOC>
class ACE_Allocator_Adapter : public ACE_Allocator