3 //==========================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu> and
8 * Irfan Pyarali <irfan@cs.wustl.edu>
10 //==========================================================================
12 #ifndef ACE_MALLOC_T_H
13 #define ACE_MALLOC_T_H
14 #include /**/ "ace/pre.h"
16 #include "ace/Malloc.h" /* Need ACE_Control_Block */
17 #include "ace/Malloc_Base.h" /* Need ACE_Allocator */
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Malloc_Allocator.h"
24 #include "ace/Free_List.h"
25 #include "ace/Guard_T.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 * @class ACE_Cached_Mem_Pool_Node
32 * @brief ACE_Cached_Mem_Pool_Node keeps unused memory within a free
35 * The length of a piece of unused memory must be greater than
36 * sizeof (void*). This makes sense because we'll waste even
37 * more memory if we keep them in a separate data structure.
38 * This class should really be placed within the ACE_Cached_Allocator
39 * class but this can't be done due to C++ compiler portability problems.
42 class ACE_Cached_Mem_Pool_Node
45 /// Return the address of free memory.
48 /// Get the next ACE_Cached_Mem_Pool_Node in a list.
49 ACE_Cached_Mem_Pool_Node
<T
> *get_next ();
51 /// Set the next ACE_Cached_Mem_Pool_Node.
52 void set_next (ACE_Cached_Mem_Pool_Node
<T
> *ptr
);
54 ACE_ALLOC_HOOK_DECLARE
;
58 * Since memory is not used when placed in a free list,
59 * we can use it to maintain the structure of free list.
60 * I was using union to hide the fact of overlapping memory
61 * usage. However, that cause problem on MSVC. So, I now turn
62 * back to hack this with casting.
64 ACE_Cached_Mem_Pool_Node
<T
> *next_
;
68 * @class ACE_Cached_Allocator
70 * @brief A fixed-size allocator that caches items for quicker access.
72 * This class enables caching of dynamically allocated,
73 * fixed-sized classes. Notice that the <code>sizeof (TYPE)</code>
74 * must be greater than or equal to <code> sizeof (void*) </code> for
75 * this to work properly.
77 * This class can be configured flexibly with different types of
78 * ACE_LOCK strategies that support the @a ACE_Thread_Mutex,
79 * @a ACE_Thread_Semaphore, @a ACE_Process_Mutex, and @a
80 * ACE_Process_Semaphore constructor API.
82 * @sa ACE_Dynamic_Cached_Allocator
84 template <class T
, class ACE_LOCK
>
85 class ACE_Cached_Allocator
: public ACE_New_Allocator
88 /// Create a cached memory pool with @a n_chunks chunks
89 /// each with sizeof (TYPE) size.
90 ACE_Cached_Allocator (size_t n_chunks
);
93 ~ACE_Cached_Allocator ();
96 * Get a chunk of memory from free list cache. Note that @a nbytes is
97 * only checked to make sure that it's less or equal to sizeof T, and is
98 * otherwise ignored since @c malloc() always returns a pointer to an
101 void *malloc (size_t nbytes
= sizeof (T
));
104 * Get a chunk of memory from free list cache, giving them
105 * @a initial_value. Note that @a nbytes is only checked to make sure
106 * that it's less or equal to sizeof T, and is otherwise ignored since
107 * calloc() always returns a pointer to an item of sizeof (T).
109 virtual void *calloc (size_t nbytes
,
110 char initial_value
= '\0');
112 /// This method is a no-op and just returns 0 since the free list
113 /// only works with fixed sized entities.
114 virtual void *calloc (size_t n_elem
,
116 char initial_value
= '\0');
118 /// Return a chunk of memory back to free list cache.
121 /// Return the number of chunks available in the cache.
122 size_t pool_depth ();
124 ACE_ALLOC_HOOK_DECLARE
;
127 /// Remember how we allocate the memory in the first place so
128 /// we can clear things up later.
131 /// Maintain a cached memory free list.
132 ACE_Locked_Free_List
<ACE_Cached_Mem_Pool_Node
<T
>, ACE_LOCK
> free_list_
;
136 * @class ACE_Dynamic_Cached_Allocator
138 * @brief A size-based allocator that caches blocks for quicker access.
140 * This class enables caching of dynamically allocated,
141 * fixed-size chunks. Notice that the <code>chunk_size</code>
142 * must be greater than or equal to <code> sizeof (void*) </code> for
143 * this to work properly.
145 * This class can be configured flexibly with different types of
146 * ACE_LOCK strategies that support the @a ACE_Thread_Mutex and @a
147 * ACE_Process_Mutex constructor API.
149 * @sa ACE_Cached_Allocator
151 template <class ACE_LOCK
>
152 class ACE_Dynamic_Cached_Allocator
: public ACE_New_Allocator
155 /// Create a cached memory pool with @a n_chunks chunks
156 /// each with @a chunk_size size.
157 ACE_Dynamic_Cached_Allocator (size_t n_chunks
, size_t chunk_size
);
160 ~ACE_Dynamic_Cached_Allocator ();
163 * Get a chunk of memory from free list cache. Note that @a nbytes is
164 * only checked to make sure that it's less or equal to @a chunk_size,
165 * and is otherwise ignored since malloc() always returns a pointer to an
166 * item of @a chunk_size size.
168 void *malloc (size_t nbytes
= 0);
171 * Get a chunk of memory from free list cache, giving them
172 * @a initial_value. Note that @a nbytes is only checked to make sure
173 * that it's less or equal to @a chunk_size, and is otherwise ignored
174 * since calloc() always returns a pointer to an item of @a chunk_size.
176 virtual void *calloc (size_t nbytes
,
177 char initial_value
= '\0');
179 /// This method is a no-op and just returns 0 since the free list
180 /// only works with fixed sized entities.
181 virtual void *calloc (size_t n_elem
,
183 char initial_value
= '\0');
185 /// Return a chunk of memory back to free list cache.
188 /// Return the number of chunks available in the cache.
189 size_t pool_depth ();
192 /// Remember how we allocate the memory in the first place so
193 /// we can clear things up later.
196 /// Maintain a cached memory free list. We use @c char as template
197 /// parameter, although sizeof(char) is usually less than
198 /// sizeof(void*). Really important is that @a chunk_size
199 /// must be greater or equal to sizeof(void*).
200 ACE_Locked_Free_List
<ACE_Cached_Mem_Pool_Node
<char>, ACE_LOCK
> free_list_
;
202 /// Remember the size of our chunks.
207 * @class ACE_Allocator_Adapter
209 * @brief This class is an adapter that allows the ACE_Allocator to
210 * use the ACE_Malloc class below.
212 template <class MALLOC
>
213 class ACE_Allocator_Adapter
: public ACE_Allocator
217 typedef MALLOC ALLOCATOR
;
218 typedef const typename
MALLOC::MEMORY_POOL_OPTIONS
*MEMORY_POOL_OPTIONS
;
222 * Note that @a pool_name should be located in
223 * a directory with the appropriate visibility and protection so
224 * that all processes that need to access it can do so. */
225 ACE_Allocator_Adapter (const char *pool_name
= 0);
228 * Note that @a pool_name should be located in
229 * a directory with the appropriate visibility and protection so
230 * that all processes that need to access it can do so.
232 ACE_Allocator_Adapter (const char *pool_name
,
233 const char *lock_name
,
234 MEMORY_POOL_OPTIONS options
= 0);
236 #if defined (ACE_HAS_WCHAR)
238 * Note that @a pool_name should be located in
239 * a directory with the appropriate visibility and protection so
240 * that all processes that need to access it can do so. */
241 ACE_Allocator_Adapter (const wchar_t *pool_name
);
244 * Note that @a pool_name should be located in
245 * a directory with the appropriate visibility and protection so
246 * that all processes that need to access it can do so.
248 ACE_Allocator_Adapter (const wchar_t *pool_name
,
249 const wchar_t *lock_name
,
250 MEMORY_POOL_OPTIONS options
= 0);
251 #endif /* ACE_HAS_WCHAR */
254 virtual ~ACE_Allocator_Adapter ();
256 // = Memory Management
258 /// Allocate @a nbytes, but don't give them any initial value.
259 virtual void *malloc (size_t nbytes
);
261 /// Allocate @a nbytes, giving them all an @a initial_value.
262 virtual void *calloc (size_t nbytes
, char initial_value
= '\0');
264 /// Allocate @a n_elem each of size @a elem_size, giving them
265 /// @a initial_value.
266 virtual void *calloc (size_t n_elem
,
268 char initial_value
= '\0');
270 /// Free @a ptr (must have been allocated by ACE_Allocator::malloc()).
271 virtual void free (void *ptr
);
273 /// Remove any resources associated with this memory manager.
274 virtual int remove ();
276 // = Map manager like functions
279 * Associate @a name with @a pointer. If @a duplicates == 0 then do
280 * not allow duplicate @a name/pointer associations, else if
281 * @a duplicates != 0 then allow duplicate @a name/pointer
282 * associations. Returns 0 if successfully binds (1) a previously
283 * unbound @a name or (2) @a duplicates != 0, returns 1 if trying to
284 * bind a previously bound @a name and @a duplicates == 0, else
285 * returns -1 if a resource failure occurs.
287 virtual int bind (const char *name
, void *pointer
, int duplicates
= 0);
290 * Associate @a name with @a pointer. Does not allow duplicate
291 * name/pointer associations. Returns 0 if successfully binds
292 * (1) a previously unbound @a name, 1 if trying to bind a previously
293 * bound @a name, or returns -1 if a resource failure occurs. When
294 * this call returns, @a pointer's value will always reference the
295 * void * that @a name is associated with. Thus, if the caller needs
296 * to use @a pointer (e.g., to free it) a copy must be maintained by
299 virtual int trybind (const char *name
, void *&pointer
);
301 /// Locate @a name and pass out parameter via pointer. If found,
302 /// return 0, returns -1 if @a name isn't found.
303 virtual int find (const char *name
, void *&pointer
);
305 /// Returns 0 if the name is in the mapping and -1 if not.
306 virtual int find (const char *name
);
308 /// Unbind (remove) the name from the map. Don't return the pointer
310 virtual int unbind (const char *name
);
312 /// Break any association of name. Returns the value of pointer in
313 /// case the caller needs to deallocate memory.
314 virtual int unbind (const char *name
, void *&pointer
);
316 // = Protection and "sync" (i.e., flushing data to backing store).
319 * Sync @a len bytes of the memory region to the backing store
320 * starting at @c this->base_addr_. If @a len == -1 then sync the
323 virtual int sync (ssize_t len
= -1, int flags
= MS_SYNC
);
325 /// Sync @a len bytes of the memory region to the backing store
326 /// starting at @c addr_.
327 virtual int sync (void *addr
, size_t len
, int flags
= MS_SYNC
);
330 * Change the protection of the pages of the mapped region to @a prot
331 * starting at @c this->base_addr_ up to @a len bytes. If @a len == -1
332 * then change protection of all pages in the mapped region.
334 virtual int protect (ssize_t len
= -1, int prot
= PROT_RDWR
);
336 /// Change the protection of the pages of the mapped region to @a prot
337 /// starting at @a addr up to @a len bytes.
338 virtual int protect (void *addr
, size_t len
, int prot
= PROT_RDWR
);
340 /// Returns the underlying allocator.
343 #if defined (ACE_HAS_MALLOC_STATS)
344 /// Dump statistics of how malloc is behaving.
345 virtual void print_stats () const;
346 #endif /* ACE_HAS_MALLOC_STATS */
348 /// Dump the state of the object.
349 virtual void dump () const;
351 ACE_ALLOC_HOOK_DECLARE
;
354 /// ALLOCATOR instance, which is owned by the adapter.
355 ALLOCATOR allocator_
;
359 * @class ACE_Static_Allocator
361 * @brief Defines a class that provided a highly optimized memory
362 * management scheme for allocating memory statically.
364 * This class allocates a fixed-size @c POOL_SIZE of memory and
365 * uses the ACE_Static_Allocator_Base class implementations of
366 * malloc() and calloc() to optimize memory allocation from this
369 template <size_t POOL_SIZE
>
370 class ACE_Static_Allocator
: public ACE_Static_Allocator_Base
373 ACE_Static_Allocator ()
374 : ACE_Static_Allocator_Base (pool_
, POOL_SIZE
)
376 // This function <{must}> be inlined!!!
381 char pool_
[POOL_SIZE
];
384 // Forward declaration.
385 template <ACE_MEM_POOL_1
, class ACE_LOCK
, class ACE_CB
>
386 class ACE_Malloc_LIFO_Iterator_T
;
388 // Ensure backwards compatibility...
389 #define ACE_Malloc_Iterator ACE_Malloc_LIFO_Iterator
391 // Forward declaration.
392 template <ACE_MEM_POOL_1
, class ACE_LOCK
, class ACE_CB
>
393 class ACE_Malloc_FIFO_Iterator_T
;
396 * @class ACE_Malloc_T
398 * @brief A class template that uses parameterized types to provide
399 * an extensible mechanism for encapsulating various dynamic
400 * memory management strategies.
402 * This class can be configured flexibly with different
403 * MEMORY_POOL strategies and different types of ACE_LOCK
404 * strategies that support the ACE_Thread_Mutex and ACE_Process_Mutex
407 * Common MEMORY_POOL strategies to use with this class are:
408 * - ACE_Local_Memory_Pool
409 * - ACE_MMAP_Memory_Pool
410 * - ACE_Pagefile_Memory_Pool
411 * - ACE_Shared_Memory_Pool
412 * - ACE_Sbrk_Memory_Pool
414 * The MEMORY_POOL class must provide the following methods:
415 * - constructor (const ACE_TCHAR *pool_name)
416 * - constructor (const ACE_TCHAR *pool_name, const MEMORY_POOL_OPTIONS *options)
417 * - void dump () const (needed if ACE is built with ACE_HAS_DUMP defined)
418 * - void *init_acquire (size_t nbytes, size_t &rounded_bytes, int &first_time);
420 * - void *acquire (size_t nbytes, size_t &rounded_bytes)
421 * - void *base_addr ()
422 * - seh_selector() (only needed on Windows)
424 * Note that the ACE_Allocator_Adapter class can be used to integrate allocator
425 * classes which do not meet the interface requirements of ACE_Malloc_T.
427 * @Note The bind() and find() methods use linear search, so
428 * it's not a good idea to use them for managing a large number of
429 * entities. If you need to manage a large number of entities, it's
430 * recommended that you bind() an ACE_Hash_Map_Manager that
431 * resides in shared memory, use find() to locate it, and then
432 * store/retrieve the entities in the hash map.
434 template <ACE_MEM_POOL_1
, class ACE_LOCK
, class ACE_CB
>
438 friend class ACE_Malloc_LIFO_Iterator_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
>;
439 friend class ACE_Malloc_FIFO_Iterator_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
>;
440 typedef ACE_MEM_POOL MEMORY_POOL
;
441 typedef ACE_MEM_POOL_OPTIONS MEMORY_POOL_OPTIONS
;
442 typedef typename
ACE_CB::ACE_Name_Node NAME_NODE
;
443 typedef typename
ACE_CB::ACE_Malloc_Header MALLOC_HEADER
;
446 * Initialize ACE_Malloc. This constructor passes @a pool_name to
447 * initialize the memory pool, and uses ACE::basename() to
448 * automatically extract out the name used for the underlying lock
449 * name (if necessary).
451 * Note that @a pool_name should be located in
452 * a directory with the appropriate visibility and protection so
453 * that all processes that need to access it can do so.
455 ACE_Malloc_T (const ACE_TCHAR
*pool_name
= 0);
458 * Initialize ACE_Malloc. This constructor passes @a pool_name to
459 * initialize the memory pool, and uses @a lock_name to automatically
460 * extract out the name used for the underlying lock name (if
461 * necessary). In addition, @a options is passed through to
462 * initialize the underlying memory pool.
464 * Note that @a pool_name should be located in
465 * a directory with the appropriate visibility and protection so
466 * that all processes that need to access it can do so.
468 ACE_Malloc_T (const ACE_TCHAR
*pool_name
,
469 const ACE_TCHAR
*lock_name
,
470 const ACE_MEM_POOL_OPTIONS
*options
= 0);
473 * Initialize an ACE_Malloc with an external ACE_LOCK.
474 * This constructor passes @a pool_name and @a options to initialize
475 * the memory pool. @a lock is used as the pool lock, and must be
476 * properly set up and ready for use before being passed to this method.
478 ACE_Malloc_T (const ACE_TCHAR
*pool_name
,
479 const ACE_MEM_POOL_OPTIONS
*options
,
485 /// Get Reference counter.
488 /// Release ref counter.
489 /// @retval 0 Success
490 /// @retval -1 Failure to missing control block
491 /// @retval >0 Memory not release because refcount is not zero
492 int release (int close
= 0);
494 /// Releases resources allocated by this object.
497 // = Memory management
499 /// Allocate @a nbytes, but don't give them any initial value.
500 void *malloc (size_t nbytes
);
502 /// Allocate @a nbytes, giving them @a initial_value.
503 void *calloc (size_t nbytes
, char initial_value
= '\0');
505 /// Allocate @a n_elem each of size @a elem_size, giving them
506 /// @a initial_value.
507 void *calloc (size_t n_elem
,
509 char initial_value
= '\0');
511 /// Deallocate memory pointed to by @a ptr, which must have been
512 /// allocated previously by malloc().
513 void free (void *ptr
);
515 /// Returns a reference to the underlying memory pool.
516 MEMORY_POOL
&memory_pool ();
518 // = Map manager like functions
521 * Associate @a name with @a pointer. If @a duplicates == 0 then do
522 * not allow duplicate name/pointer associations, else if
523 * @a duplicates != 0 then allow duplicate name/pointer
524 * associations. Returns 0 if successfully binds (1) a previously
525 * unbound @a name or (2) @a duplicates != 0, returns 1 if trying to
526 * bind a previously bound @a name and @a duplicates == 0, else
527 * returns -1 if a resource failure occurs.
529 int bind (const char *name
, void *pointer
, int duplicates
= 0);
532 * Associate @a name with @a pointer. Does not allow duplicate
533 * name/pointer associations. Returns 0 if successfully binds
534 * (1) a previously unbound @a name, 1 if trying to bind a previously
535 * bound @a name, or returns -1 if a resource failure occurs. When
536 * this call returns @a pointer's value will always reference the
537 * void * that @a name is associated with. Thus, if the caller needs
538 * to use @a pointer (e.g., to free it) a copy must be maintained by
541 int trybind (const char *name
, void *&pointer
);
543 /// Locate @a name and pass out parameter via @a pointer. If found,
544 /// return 0, returns -1 if failure occurs.
545 int find (const char *name
, void *&pointer
);
547 /// Returns 0 if @a name is in the mapping. -1, otherwise.
548 int find (const char *name
);
551 * Unbind (remove) the name from the map. Don't return the pointer
552 * to the caller. If you want to remove all occurrences of @a name
553 * you'll need to call this method multiple times until it fails...
555 int unbind (const char *name
);
558 * Unbind (remove) one association of @a name to @a pointer. Returns
559 * the value of pointer in case the caller needs to deallocate
560 * memory. If you want to remove all occurrences of @a name you'll
561 * need to call this method multiple times until it fails...
563 int unbind (const char *name
, void *&pointer
);
565 // = Protection and "sync" (i.e., flushing data to backing store).
568 * Sync @a len bytes of the memory region to the backing store
569 * starting at @c this->base_addr_. If @a len == -1 then sync the
572 int sync (ssize_t len
= -1, int flags
= MS_SYNC
);
574 /// Sync @a len bytes of the memory region to the backing store
575 /// starting at @c addr_.
576 int sync (void *addr
, size_t len
, int flags
= MS_SYNC
);
579 * Change the protection of the pages of the mapped region to @a prot
580 * starting at @c this->base_addr_ up to @a len bytes. If @a len == -1
581 * then change protection of all pages in the mapped region.
583 int protect (ssize_t len
= -1, int prot
= PROT_RDWR
);
585 /// Change the protection of the pages of the mapped region to @a prot
586 /// starting at @a addr up to @a len bytes.
587 int protect (void *addr
, size_t len
, int prot
= PROT_RDWR
);
590 * Returns a count of the number of available chunks that can hold
591 * @a size byte allocations. Function can be used to determine if you
592 * have reached a water mark. This implies a fixed amount of allocated
595 * @param size The chunk size of that you would like a count of
596 * @return Function returns the number of chunks of the given size
597 * that would fit in the currently allocated memory.
599 ssize_t
avail_chunks (size_t size
) const;
601 #if defined (ACE_HAS_MALLOC_STATS)
602 /// Dump statistics of how malloc is behaving.
603 void print_stats () const;
604 #endif /* ACE_HAS_MALLOC_STATS */
606 /// Returns a pointer to the lock used to provide mutual exclusion to
607 /// an ACE_Malloc allocator.
610 /// Dump the state of an object.
613 /// Declare the dynamic allocation hooks.
614 ACE_ALLOC_HOOK_DECLARE
;
616 /// Return cb_ptr value.
620 * Bad flag. This operation should be called immediately after the
621 * construction of the Malloc object to query whether the object was
622 * constructed successfully. If not, the user should invoke @c
623 * remove and release the object (it is not usable.)
624 * @retval 0 if all is fine. non-zero if this malloc object is
630 /// Initialize the Malloc pool.
633 /// Associate @a name with @a pointer. Assumes that locks are held by
635 int shared_bind (const char *name
,
639 * Try to locate @a name. If found, return the associated
640 * ACE_Name_Node, else returns 0 if can't find the @a name.
641 * Assumes that locks are held by callers. Remember to cast the
642 * return value to ACE_CB::ACE_Name_Node*.
644 void *shared_find (const char *name
);
646 /// Allocate memory. Assumes that locks are held by callers.
647 void *shared_malloc (size_t nbytes
);
649 /// Deallocate memory. Assumes that locks are held by callers.
650 void shared_free (void *ptr
);
652 /// Pointer to the control block that is stored in memory controlled
653 /// by <MEMORY_POOL>.
656 /// Pool of memory used by ACE_Malloc to manage its freestore.
657 MEMORY_POOL memory_pool_
;
659 /// Lock that ensures mutual exclusion for the memory pool.
662 /// True if destructor should delete the lock
665 /// Keep track of failure in constructor.
669 /*****************************************************************************/
672 * @class ACE_Malloc_Lock_Adapter_T
674 * @brief Template functor adapter for lock strategies used with ACE_Malloc_T.
676 * This class acts as a factory for lock strategies that have various ctor
677 * signatures. If the lock strategy's ctor takes an ACE_TCHAR* as the first
678 * and only required parameter, it will just work. Otherwise use template
679 * specialization to create a version that matches the lock strategy's ctor
680 * signature. See ACE_Process_Semaphore and ACE_Thread_Semaphore for
683 /*****************************************************************************/
686 * @class ACE_Malloc_LIFO_Iterator_T
688 * @brief LIFO iterator for names stored in Malloc'd memory.
690 * This class can be configured flexibly with different types of
691 * ACE_LOCK strategies that support the @a ACE_Thread_Mutex and @a
692 * ACE_Process_Mutex constructor API.
694 * Does not support deletions while iteration is occurring.
696 template <ACE_MEM_POOL_1
, class ACE_LOCK
, class ACE_CB
>
697 class ACE_Malloc_LIFO_Iterator_T
700 typedef typename
ACE_CB::ACE_Name_Node NAME_NODE
;
701 typedef typename
ACE_CB::ACE_Malloc_Header MALLOC_HEADER
;
703 /// If @a name = 0 it will iterate through everything else only
704 /// through those entries whose @a name match.
705 ACE_Malloc_LIFO_Iterator_T (ACE_Malloc_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
> &malloc
,
706 const char *name
= 0);
709 ~ACE_Malloc_LIFO_Iterator_T ();
711 // = Iteration methods.
713 /// Returns 1 when all items have been seen, else 0.
716 /// Pass back the next entry in the set that hasn't yet been
717 /// visited. Returns 0 when all items have been seen, else 1.
718 int next (void *&next_entry
);
721 * Pass back the next entry (and the name associated with it) in
722 * the set that hasn't yet been visited. Returns 0 when all items
723 * have been seen, else 1.
725 int next (void *&next_entry
, const char *&name
);
727 /// Move forward by one element in the set. Returns 0 when all the
728 /// items in the set have been seen, else 1.
731 /// Dump the state of an object.
734 /// Declare the dynamic allocation hooks.
735 ACE_ALLOC_HOOK_DECLARE
;
738 /// Malloc we are iterating over.
739 ACE_Malloc_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
> &malloc_
;
741 /// Keeps track of how far we've advanced...
744 // FUZZ: disable check_for_ACE_Guard
745 /// Lock Malloc for the lifetime of the iterator.
746 ACE_Read_Guard
<ACE_LOCK
> guard_
;
747 // FUZZ: enable check_for_ACE_Guard
749 /// Name that we are searching for.
754 * @class ACE_Malloc_FIFO_Iterator_T
756 * @brief FIFO iterator for names stored in Malloc'd memory.
758 * This class can be configured flexibly with different types of
759 * ACE_LOCK strategies that support the @a ACE_Thread_Mutex and @a
760 * ACE_Process_Mutex constructor API.
762 * Does not support deletions while iteration is occurring.
764 template <ACE_MEM_POOL_1
, class ACE_LOCK
, class ACE_CB
>
765 class ACE_Malloc_FIFO_Iterator_T
768 typedef typename
ACE_CB::ACE_Name_Node NAME_NODE
;
769 typedef typename
ACE_CB::ACE_Malloc_Header MALLOC_HEADER
;
771 /// If @a name = 0 it will iterate through everything else only
772 /// through those entries whose @a name match.
773 ACE_Malloc_FIFO_Iterator_T (ACE_Malloc_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
> &malloc
,
774 const char *name
= 0);
777 ~ACE_Malloc_FIFO_Iterator_T ();
779 // = Iteration methods.
781 /// Returns 1 when all items have been seen, else 0.
784 /// Pass back the next entry in the set that hasn't yet been
785 /// visited. Returns 0 when all items have been seen, else 1.
786 int next (void *&next_entry
);
789 * Pass back the next entry (and the name associated with it) in
790 * the set that hasn't yet been visited. Returns 0 when all items
791 * have been seen, else 1.
793 int next (void *&next_entry
, const char *&name
);
795 /// Move forward by one element in the set. Returns 0 when all the
796 /// items in the set have been seen, else 1.
799 /// Go to the starting element that was inserted first. Returns 0
800 /// when there is no item in the set, else 1.
803 /// Dump the state of an object.
806 /// Declare the dynamic allocation hooks.
807 ACE_ALLOC_HOOK_DECLARE
;
810 /// Malloc we are iterating over.
811 ACE_Malloc_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_CB
> &malloc_
;
813 /// Keeps track of how far we've advanced...
816 // FUZZ: disable check_for_ACE_Guard
817 /// Lock Malloc for the lifetime of the iterator.
818 ACE_Read_Guard
<ACE_LOCK
> guard_
;
819 // FUZZ: enable check_for_ACE_Guard
821 /// Name that we are searching for.
825 template <ACE_MEM_POOL_1
, class ACE_LOCK
>
826 class ACE_Malloc
: public ACE_Malloc_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_Control_Block
>
830 * Initialize ACE_Malloc. This constructor passes @a pool_name to
831 * initialize the memory pool, and uses ACE::basename() to
832 * automatically extract out the name used for the underlying lock
833 * name (if necessary). Note that @a pool_name should be located in
834 * a directory with the appropriate visibility and protection so
835 * that all processes that need to access it can do so.
837 ACE_Malloc (const ACE_TCHAR
*pool_name
= 0);
840 * Initialize ACE_Malloc. This constructor passes @a pool_name to
841 * initialize the memory pool, and uses @a lock_name to automatically
842 * extract out the name used for the underlying lock name (if
843 * necessary). In addition, @a options is passed through to
844 * initialize the underlying memory pool. Note that @a pool_name
845 * should be located in a directory with the appropriate visibility
846 * and protection so that all processes that need to access it can
849 ACE_Malloc (const ACE_TCHAR
*pool_name
,
850 const ACE_TCHAR
*lock_name
,
851 const ACE_MEM_POOL_OPTIONS
*options
= 0);
854 template <ACE_MEM_POOL_1
, class ACE_LOCK
>
855 class ACE_Malloc_LIFO_Iterator
: public ACE_Malloc_LIFO_Iterator_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_Control_Block
>
858 /// If @a name = 0 it will iterate through everything else only
859 /// through those entries whose @a name match.
860 ACE_Malloc_LIFO_Iterator (ACE_Malloc
<ACE_MEM_POOL_2
, ACE_LOCK
> &malloc
,
861 const char *name
= 0);
864 template <ACE_MEM_POOL_1
, class ACE_LOCK
>
865 class ACE_Malloc_FIFO_Iterator
: public ACE_Malloc_FIFO_Iterator_T
<ACE_MEM_POOL_2
, ACE_LOCK
, ACE_Control_Block
>
868 /// If @a name = 0 it will iterate through everything else only
869 /// through those entries whose @a name match.
870 ACE_Malloc_FIFO_Iterator (ACE_Malloc
<ACE_MEM_POOL_2
, ACE_LOCK
> &malloc
,
871 const char *name
= 0);
874 template <class ACE_LOCK
>
875 class ACE_Malloc_Lock_Adapter_T
878 ACE_LOCK
* operator () (const ACE_TCHAR
*myname
);
881 ACE_END_VERSIONED_NAMESPACE_DECL
883 #if defined (__ACE_INLINE__)
884 #include "ace/Malloc_T.inl"
885 #endif /* __ACE_INLINE__ */
887 #include "ace/Malloc_T.cpp"
889 #include /**/ "ace/post.h"
890 #endif /* ACE_MALLOC_H */