Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Malloc_Base.h
blob6a13d020ad676760b8c49c586f25e556dcf04e10
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Malloc_Base.h
7 * $Id: Malloc_Base.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Doug Schmidt and Irfan Pyarali
11 //=============================================================================
14 #ifndef ACE_MALLOC_BASE_H
15 #define ACE_MALLOC_BASE_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/os_include/sys/os_types.h"
25 #include "ace/os_include/sys/os_mman.h"
26 #include "ace/os_include/sys/os_types.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 // The definition of this class is located in Malloc.cpp.
32 /**
33 * @class ACE_Allocator
35 * @brief Interface for a dynamic memory allocator that uses inheritance
36 * and dynamic binding to provide extensible mechanisms for
37 * allocating and deallocating memory.
39 class ACE_Export ACE_Allocator
41 public:
43 /// Unsigned integer type used for specifying memory block lengths.
44 typedef size_t size_type;
46 // = Memory Management
48 /// Get pointer to a default ACE_Allocator.
49 static ACE_Allocator *instance (void);
51 /// Set pointer to a process-wide ACE_Allocator and return existing
52 /// pointer.
53 static ACE_Allocator *instance (ACE_Allocator *);
55 /// Delete the dynamically allocated Singleton
56 static void close_singleton (void);
58 /// "No-op" constructor (needed to make certain compilers happy).
59 ACE_Allocator (void);
61 /// Virtual destructor
62 virtual ~ACE_Allocator (void);
64 /// Allocate @a nbytes, but don't give them any initial value.
65 virtual void *malloc (size_type nbytes) = 0;
67 /// Allocate @a nbytes, giving them @a initial_value.
68 virtual void *calloc (size_type nbytes, char initial_value = '\0') = 0;
70 /// Allocate <n_elem> each of size @a elem_size, giving them
71 /// @a initial_value.
72 virtual void *calloc (size_type n_elem,
73 size_type elem_size,
74 char initial_value = '\0') = 0;
76 /// Free <ptr> (must have been allocated by <ACE_Allocator::malloc>).
77 virtual void free (void *ptr) = 0;
79 /// Remove any resources associated with this memory manager.
80 virtual int remove (void) = 0;
82 // = Map manager like functions
84 /**
85 * Associate @a name with @a pointer. If @a duplicates == 0 then do
86 * not allow duplicate @a name/@a pointer associations, else if
87 * @a duplicates != 0 then allow duplicate @a name/@a pointer
88 * assocations. Returns 0 if successfully binds (1) a previously
89 * unbound @a name or (2) @a duplicates != 0, returns 1 if trying to
90 * bind a previously bound @a name and @a duplicates == 0, else
91 * returns -1 if a resource failure occurs.
93 virtual int bind (const char *name, void *pointer, int duplicates = 0) = 0;
95 /**
96 * Associate @a name with @a pointer. Does not allow duplicate
97 * @a name/@a pointer associations. Returns 0 if successfully binds
98 * (1) a previously unbound @a name, 1 if trying to bind a previously
99 * bound @a name, or returns -1 if a resource failure occurs. When
100 * this call returns @a pointer's value will always reference the
101 * void * that @a name is associated with. Thus, if the caller needs
102 * to use @a pointer (e.g., to free it) a copy must be maintained by
103 * the caller.
105 virtual int trybind (const char *name, void *&pointer) = 0;
107 /// Locate @a name and pass out parameter via pointer. If found,
108 /// return 0, returns -1 if failure occurs.
109 virtual int find (const char *name, void *&pointer) = 0;
111 /// Returns 0 if the name is in the mapping. -1, otherwise.
112 virtual int find (const char *name) = 0;
114 /// Unbind (remove) the name from the map. Don't return the pointer
115 /// to the caller
116 virtual int unbind (const char *name) = 0;
118 /// Break any association of name. Returns the value of pointer in
119 /// case the caller needs to deallocate memory.
120 virtual int unbind (const char *name, void *&pointer) = 0;
122 // = Protection and "sync" (i.e., flushing memory to persistent
123 // backing store).
126 * Sync @a len bytes of the memory region to the backing store
127 * starting at @c this->base_addr_. If @a len == -1 then sync the
128 * whole region.
130 virtual int sync (ssize_t len = -1, int flags = MS_SYNC) = 0;
132 /// Sync @a len bytes of the memory region to the backing store
133 /// starting at @a addr.
134 virtual int sync (void *addr, size_type len, int flags = MS_SYNC) = 0;
137 * Change the protection of the pages of the mapped region to @a prot
138 * starting at <this->base_addr_> up to @a len bytes. If @a len == -1
139 * then change protection of all pages in the mapped region.
141 virtual int protect (ssize_t len = -1, int prot = PROT_RDWR) = 0;
143 /// Change the protection of the pages of the mapped region to @a prot
144 /// starting at @a addr up to @a len bytes.
145 virtual int protect (void *addr, size_type len, int prot = PROT_RDWR) = 0;
147 #if defined (ACE_HAS_MALLOC_STATS)
148 /// Dump statistics of how malloc is behaving.
149 virtual void print_stats (void) const = 0;
150 #endif /* ACE_HAS_MALLOC_STATS */
152 /// Dump the state of the object.
153 virtual void dump (void) const = 0;
154 private:
155 // DO NOT ADD ANY STATE (DATA MEMBERS) TO THIS CLASS!!!! See the
156 // <ACE_Allocator::instance> implementation for explanation.
158 /// Pointer to a process-wide ACE_Allocator instance.
159 static ACE_Allocator *allocator_;
161 /// Must delete the <allocator_> if non-0.
162 static int delete_allocator_;
165 ACE_END_VERSIONED_NAMESPACE_DECL
167 #include /**/ "ace/post.h"
168 #endif /* ACE_MALLOC_BASE_H */