3 //==========================================================================
5 * @file Malloc_Allocator.h
7 * @author Based on code that formerly existed in another ACE file.
9 //==========================================================================
11 #ifndef ACE_MALLOC_ALLOCATOR_H
12 #define ACE_MALLOC_ALLOCATOR_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Malloc_Base.h"
24 #if defined (ACE_HAS_MALLOC_STATS)
25 #if defined (ACE_HAS_THREADS)
26 #include "ace/Process_Mutex.h"
27 #define ACE_PROCESS_MUTEX ACE_Process_Mutex
29 #include "ace/SV_Semaphore_Simple.h"
30 #define ACE_PROCESS_MUTEX ACE_SV_Semaphore_Simple
31 #endif /* ACE_HAS_THREADS */
33 #endif /* ACE_HAS_MALLOC_STATS */
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 * @class ACE_New_Allocator
40 * @brief Defines a class that provided a simple implementation of
43 * This class uses the new/delete operators to allocate and free up
44 * memory. Please note that the only methods that are supported are
45 * malloc(), calloc(), and free(). All other methods are no-ops that
46 * return -1 and set @c errno to @c ENOTSUP. If you require this
47 * functionality, please use: ACE_Allocator_Adapter <ACE_Malloc
48 * <ACE_LOCAL_MEMORY_POOL, MUTEX> >, which will allow you to use the
49 * added functionality of bind/find/etc. while using the new/delete
52 class ACE_Export ACE_New_Allocator
: public ACE_Allocator
55 /// These methods are defined.
56 virtual void *malloc (size_t nbytes
);
57 virtual void *calloc (size_t nbytes
, char initial_value
= '\0');
58 virtual void *calloc (size_t n_elem
, size_t elem_size
, char initial_value
= '\0');
59 virtual void free (void *ptr
);
61 /// These methods are no-ops.
62 virtual int remove ();
63 virtual int bind (const char *name
, void *pointer
, int duplicates
= 0);
64 virtual int trybind (const char *name
, void *&pointer
);
65 virtual int find (const char *name
, void *&pointer
);
66 virtual int find (const char *name
);
67 virtual int unbind (const char *name
);
68 virtual int unbind (const char *name
, void *&pointer
);
69 virtual int sync (ssize_t len
= -1, int flags
= MS_SYNC
);
70 virtual int sync (void *addr
, size_t len
, int flags
= MS_SYNC
);
71 virtual int protect (ssize_t len
= -1, int prot
= PROT_RDWR
);
72 virtual int protect (void *addr
, size_t len
, int prot
= PROT_RDWR
);
73 #if defined (ACE_HAS_MALLOC_STATS)
74 virtual void print_stats () const;
75 #endif /* ACE_HAS_MALLOC_STATS */
76 virtual void dump () const;
79 // DO NOT ADD ANY STATE (DATA MEMBERS) TO THIS CLASS!!!! See the
80 // <ACE_Allocator::instance> implementation for explanation.
84 * @class ACE_Static_Allocator_Base
86 * @brief Defines a class that provided a highly optimized memory
87 * management scheme for allocating memory statically.
89 * This class manages a fixed-size @c POOL_SIZE of memory. Every
90 * time malloc()/calloc() is called, it simply moves an internal
91 * index forward and returns a pointer to the requested chunk.
92 * All memory is allocated statically (typically via the
93 * ACE_Static_Allocator template) and free() is a no-op. This
94 * behavior is useful for use-cases where all the memory
95 * allocation needs are known in advance and no deletions ever
98 class ACE_Export ACE_Static_Allocator_Base
: public ACE_Allocator
101 ACE_Static_Allocator_Base (char *buffer
, size_t size
);
102 virtual void *malloc (size_t nbytes
);
103 virtual void *calloc (size_t nbytes
, char initial_value
= '\0');
104 virtual void *calloc (size_t n_elem
, size_t elem_size
, char initial_value
= '\0');
105 virtual void free (void *ptr
);
106 virtual int remove ();
107 virtual int bind (const char *name
, void *pointer
, int duplicates
= 0);
108 virtual int trybind (const char *name
, void *&pointer
);
109 virtual int find (const char *name
, void *&pointer
);
110 virtual int find (const char *name
);
111 virtual int unbind (const char *name
);
112 virtual int unbind (const char *name
, void *&pointer
);
113 virtual int sync (ssize_t len
= -1, int flags
= MS_SYNC
);
114 virtual int sync (void *addr
, size_t len
, int flags
= MS_SYNC
);
115 virtual int protect (ssize_t len
= -1, int prot
= PROT_RDWR
);
116 virtual int protect (void *addr
, size_t len
, int prot
= PROT_RDWR
);
117 #if defined (ACE_HAS_MALLOC_STATS)
118 virtual void print_stats () const;
119 #endif /* ACE_HAS_MALLOC_STATS */
120 virtual void dump () const;
123 /// Don't allow direct instantiations of this class.
124 ACE_Static_Allocator_Base ();
126 /// Pointer to the buffer.
129 /// Size of the buffer.
132 /// Pointer to the current offset in the <buffer_>.
136 ACE_END_VERSIONED_NAMESPACE_DECL
138 #if defined (__ACE_INLINE__)
139 #include "ace/Malloc_Allocator.inl"
140 #endif /* __ACE_INLINE__ */
142 #include /**/ "ace/post.h"
144 #endif /* MALLOC_ALLOCATOR_H */