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/ACE_export.h"
00020
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif
00024
00025 #include "ace/OS_Errno.h"
00026 #include "ace/Basic_Types.h"
00027 #include "ace/os_include/os_stddef.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #if !defined (ACE_MALLOC_FUNC)
00047 # define ACE_MALLOC_FUNC ::malloc
00048 #endif
00049 #if !defined (ACE_CALLOC_FUNC)
00050 # define ACE_CALLOC_FUNC ::calloc
00051 #endif
00052 #if !defined (ACE_FREE_FUNC)
00053 # define ACE_FREE_FUNC ::free
00054 #endif
00055 #if !defined (ACE_REALLOC_FUNC)
00056 # define ACE_REALLOC_FUNC ::realloc
00057 #endif
00058
00059 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00060
00061 #if defined (ACE_HAS_OLD_MALLOC)
00062 typedef char * ACE_MALLOC_T;
00063 #else
00064 typedef void * ACE_MALLOC_T;
00065 #endif
00066
00067 ACE_END_VERSIONED_NAMESPACE_DECL
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #if defined (ACE_HAS_NEW_NOTHROW)
00080 # if !defined (ACE_NEW_THROWS_EXCEPTIONS)
00081 # define ACE_NEW_THROWS_EXCEPTIONS
00082 # endif
00083 #endif
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #if !defined (ACE_del_bad_alloc)
00095 # define ACE_del_bad_alloc
00096 #endif
00097
00098 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 # if defined (__HP_aCC)
00109
00110
00111
00112 # include <new>
00113
00114
00115
00116 # if (HPUX_VERS >= 1100)
00117 # if ((__HP_aCC < 32500 && !defined (RWSTD_NO_NAMESPACE)) || \
00118 defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00119 # define ACE_bad_alloc ::std::bad_alloc
00120 # define ACE_nothrow ::std::nothrow
00121 # define ACE_nothrow_t ::std::nothrow_t
00122 # else
00123 # define ACE_bad_alloc bad_alloc
00124 # define ACE_nothrow nothrow
00125 # define ACE_nothrow_t nothrow_t
00126 # endif
00127 # elif ((__HP_aCC < 12500 && !defined (RWSTD_NO_NAMESPACE)) || \
00128 defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00129 # define ACE_bad_alloc ::std::bad_alloc
00130 # define ACE_nothrow ::std::nothrow
00131 # define ACE_nothrow_t ::std::nothrow_t
00132 # else
00133 # define ACE_bad_alloc bad_alloc
00134 # define ACE_nothrow nothrow
00135 # define ACE_nothrow_t nothrow_t
00136 # endif
00137 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00138 # elif defined (__SUNPRO_CC)
00139 # if (__SUNPRO_CC < 0x500) || (__SUNPRO_CC_COMPAT == 4)
00140 # include <exception.h>
00141
00142
00143 # define ACE_bad_alloc ::xalloc
00144 # define ACE_throw_bad_alloc throw ACE_bad_alloc ("no more memory")
00145 # else
00146 # include <new>
00147 # define ACE_bad_alloc ::std::bad_alloc
00148 # if defined (ACE_HAS_NEW_NOTHROW)
00149 # if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00150 # define ACE_nothrow ::std::nothrow
00151 # define ACE_nothrow_t ::std::nothrow_t
00152 # else
00153 # define ACE_nothrow nothrow
00154 # define ACE_nothrow_t nothrow_t
00155 # endif
00156 # endif
00157 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00158 # endif
00159 # elif defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00160 # include <new>
00161 # if !defined (ACE_bad_alloc)
00162 # define ACE_bad_alloc ::std::bad_alloc
00163 # endif
00164 # define ACE_nothrow ::std::nothrow
00165 # define ACE_nothrow_t ::std::nothrow_t
00166
00167 # if defined (ACE_HAS_MFC) && (ACE_HAS_MFC == 1)
00168 # define ACE_throw_bad_alloc AfxThrowMemoryException ()
00169 # else
00170 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00171 # endif
00172 # else
00173 # include <new>
00174 # if !defined (ACE_bad_alloc)
00175 # define ACE_bad_alloc bad_alloc
00176 # endif
00177 # define ACE_nothrow nothrow
00178 # define ACE_nothrow_t nothrow_t
00179
00180 # if defined (ACE_HAS_MFC) && (ACE_HAS_MFC == 1)
00181 # define ACE_throw_bad_alloc AfxThrowMemoryException ()
00182 # else
00183 # define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00184 # endif
00185 # endif
00186
00187 # if defined (ACE_HAS_NEW_NOTHROW)
00188 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00189 do { POINTER = new (ACE_nothrow) CONSTRUCTOR; \
00190 if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00191 } while (0)
00192 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00193 do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00194 if (POINTER == 0) { errno = ENOMEM; return; } \
00195 } while (0)
00196 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00197 do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00198 if (POINTER == 0) { errno = ENOMEM; } \
00199 } while (0)
00200
00201 # else
00202
00203 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00204 do { try { POINTER = new CONSTRUCTOR; } \
00205 catch (ACE_bad_alloc) { ACE_del_bad_alloc errno = ENOMEM; POINTER = 0; return RET_VAL; } \
00206 } while (0)
00207
00208 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00209 do { try { POINTER = new CONSTRUCTOR; } \
00210 catch (ACE_bad_alloc) { ACE_del_bad_alloc errno = ENOMEM; POINTER = 0; return; } \
00211 } while (0)
00212
00213 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00214 do { try { POINTER = new CONSTRUCTOR; } \
00215 catch (ACE_bad_alloc) { ACE_del_bad_alloc errno = ENOMEM; POINTER = 0; } \
00216 } while (0)
00217 # endif
00218
00219 #else
00220
00221 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00222 do { POINTER = new CONSTRUCTOR; \
00223 if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00224 } while (0)
00225 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00226 do { POINTER = new CONSTRUCTOR; \
00227 if (POINTER == 0) { errno = ENOMEM; return; } \
00228 } while (0)
00229 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00230 do { POINTER = new CONSTRUCTOR; \
00231 if (POINTER == 0) { errno = ENOMEM; } \
00232 } while (0)
00233
00234 # define ACE_throw_bad_alloc \
00235 void* gcc_will_complain_if_literal_0_is_returned = 0; \
00236 return gcc_will_complain_if_literal_0_is_returned
00237
00238 #endif
00239
00240 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 #if defined (ACE_OPENVMS) && (!defined (__INITIAL_POINTER_SIZE) || (__INITIAL_POINTER_SIZE < 64))
00282 inline unsigned int
00283 ACE_align_binary (unsigned int ptr, unsigned int alignment)
00284 {
00285 unsigned int const tmp = alignment - 1;
00286 return (ptr + tmp) & (~tmp);
00287 }
00288 #else
00289 inline uintptr_t
00290 ACE_align_binary (uintptr_t ptr, uintptr_t alignment)
00291 {
00292 uintptr_t const tmp = alignment - 1;
00293 return (ptr + tmp) & (~tmp);
00294 }
00295 #endif
00296
00297 #if defined (ACE_OPENVMS) && (!defined (__INITIAL_POINTER_SIZE) || (__INITIAL_POINTER_SIZE < 64))
00298
00299 inline char *
00300 ACE_ptr_align_binary (char const * ptr, unsigned int alignment)
00301 {
00302 return
00303 reinterpret_cast<char *> (
00304 ACE_align_binary (reinterpret_cast<unsigned int> (ptr), alignment));
00305 }
00306
00307
00308 inline char *
00309 ACE_ptr_align_binary (unsigned char const * ptr, unsigned int alignment)
00310 {
00311 return
00312 ACE_ptr_align_binary (reinterpret_cast<char const *> (ptr), alignment);
00313 }
00314 #else
00315
00316 inline char *
00317 ACE_ptr_align_binary (char const * ptr, uintptr_t alignment)
00318 {
00319 return
00320 reinterpret_cast<char *> (
00321 ACE_align_binary (reinterpret_cast<uintptr_t> (ptr), alignment));
00322 }
00323
00324
00325 inline char *
00326 ACE_ptr_align_binary (unsigned char const * ptr, uintptr_t alignment)
00327 {
00328 return
00329 ACE_ptr_align_binary (reinterpret_cast<char const *> (ptr), alignment);
00330 }
00331 #endif
00332
00333 ACE_END_VERSIONED_NAMESPACE_DECL
00334
00335 #include "ace/OS_NS_stdlib.h"
00336
00337 #include "ace/post.h"
00338 #endif