00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ACE_OS_MEMORY_H
00016 #define ACE_OS_MEMORY_H
00017 #include "ace/pre.h"
00018
00019 #include "ace/OS_Export.h"
00020
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif
00024
00025 #include "ace/OS_Errno.h"
00026
00027 #ifndef ACE_HAS_WINCE
00028 #include <stddef.h>
00029 #endif // ACE_HAS_WINCE
00030
00031 # if !defined (ACE_MALLOC_ALIGN)
00032 # define ACE_MALLOC_ALIGN ((int) sizeof (long))
00033 # endif
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #if !defined (ACE_MALLOC_FUNC)
00052 # define ACE_MALLOC_FUNC ::malloc
00053 #endif
00054 #if !defined (ACE_CALLOC_FUNC)
00055 # define ACE_CALLOC_FUNC ::calloc
00056 #endif
00057 #if !defined (ACE_FREE_FUNC)
00058 # define ACE_FREE_FUNC ::free
00059 #endif
00060 #if !defined (ACE_REALLOC_FUNC)
00061 # define ACE_REALLOC_FUNC ::realloc
00062 #endif
00063
00064 #if defined (ACE_HAS_OLD_MALLOC)
00065 typedef char *ACE_MALLOC_T;
00066 #else
00067 typedef void *ACE_MALLOC_T;
00068 #endif
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 # if defined (__HP_aCC)
00090
00091
00092
00093 # include <new>
00094
00095
00096
00097 # if (HPUX_VERS >= 1100)
00098 # if ((__HP_aCC < 32500 && !defined (RWSTD_NO_NAMESPACE)) || \
00099 defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00100 # define ACE_bad_alloc std::bad_alloc
00101 # define ACE_nothrow std::nothrow
00102 # define ACE_nothrow_t std::nothrow_t
00103 # else
00104 # define ACE_bad_alloc bad_alloc
00105 # define ACE_nothrow nothrow
00106 # define ACE_nothrow_t nothrow_t
00107 # endif
00108 # elif ((__HP_aCC < 12500 && !defined (RWSTD_NO_NAMESPACE)) || \
00109 defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00110 # define ACE_bad_alloc std::bad_alloc
00111 # define ACE_nothrow std::nothrow
00112 # define ACE_nothrow_t std::nothrow_t
00113 # else
00114 # define ACE_bad_alloc bad_alloc
00115 # define ACE_nothrow nothrow
00116 # define ACE_nothrow_t nothrow_t
00117 # endif
00118 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00119 # elif defined (__SUNPRO_CC)
00120 # if (__SUNPRO_CC < 0x500) || (__SUNPRO_CC_COMPAT == 4)
00121 # include <exception.h>
00122
00123
00124 # define ACE_bad_alloc ::xalloc
00125 # define ACE_throw_bad_alloc throw ACE_bad_alloc ("no more memory")
00126 # else
00127 # include <new>
00128 # define ACE_bad_alloc std::bad_alloc
00129 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00130 # endif
00131 # elif defined (__BORLANDC__) || defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00132 # include <new>
00133 # define ACE_bad_alloc std::bad_alloc
00134 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00135 # else
00136 # include <new>
00137 # define ACE_bad_alloc bad_alloc
00138 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00139 # endif
00140
00141 # if defined (ACE_HAS_NEW_NOTHROW)
00142 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00143 do { POINTER = new (ACE_nothrow) CONSTRUCTOR; \
00144 if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00145 } while (0)
00146 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00147 do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00148 if (POINTER == 0) { errno = ENOMEM; return; } \
00149 } while (0)
00150 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00151 do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00152 if (POINTER == 0) { errno = ENOMEM; } \
00153 } while (0)
00154
00155 # else
00156
00157 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00158 do { try { POINTER = new CONSTRUCTOR; } \
00159 catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return RET_VAL; } \
00160 } while (0)
00161
00162 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00163 do { try { POINTER = new CONSTRUCTOR; } \
00164 catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return; } \
00165 } while (0)
00166
00167 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00168 do { try { POINTER = new CONSTRUCTOR; } \
00169 catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; } \
00170 } while (0)
00171 # endif
00172
00173 #else
00174
00175 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00176 do { POINTER = new CONSTRUCTOR; \
00177 if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00178 } while (0)
00179 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00180 do { POINTER = new CONSTRUCTOR; \
00181 if (POINTER == 0) { errno = ENOMEM; return; } \
00182 } while (0)
00183 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00184 do { POINTER = new CONSTRUCTOR; \
00185 if (POINTER == 0) { errno = ENOMEM; } \
00186 } while (0)
00187
00188 # define ACE_throw_bad_alloc \
00189 void* gcc_will_complain_if_literal_0_is_returned = 0; \
00190 return gcc_will_complain_if_literal_0_is_returned
00191
00192 #endif
00193
00194
00195
00196
00197
00198
00199
00200 class ACE_OS_Export ACE_OS_Memory
00201 {
00202 public:
00203
00204 static void *sbrk (int brk);
00205 static void *calloc (size_t elements, size_t sizeof_elements);
00206 static void *malloc (size_t);
00207 static void *realloc (void *, size_t);
00208 static void free (void *);
00209 };
00210
00211 # if defined (ACE_HAS_INLINED_OSCALLS)
00212 # if defined (ACE_INLINE)
00213 # undef ACE_INLINE
00214 # endif
00215 # define ACE_INLINE inline
00216 # include "ace/OS_Memory.inl"
00217 # endif
00218
00219 #include "ace/post.h"
00220 #endif