198 _STATIC_ASSERT(sizeof(unsigned int) <= _ALLOCA_S_MARKER_SIZE);
199
200 #if !defined(__midl) && !defined(RC_INVOKED)
201 #pragma warning(push)
202 #pragma warning(disable:6540)
203 __inline void *_MarkAllocaS(_Out_opt_ __crt_typefix(unsigned int*) void *_Ptr, unsigned int _Marker)
204 {
205 if (_Ptr)
206 {
207 *((unsigned int*)_Ptr) = _Marker;
208 _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
209 }
210 return _Ptr;
211 }
212 #pragma warning(pop)
213 #endif
214
215 #if defined(_DEBUG)
216 #if !defined(_CRTDBG_MAP_ALLOC)
217 #undef _malloca
218 #define _malloca(size) \
219 __pragma(warning(suppress: 6255)) \
220 _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE), _ALLOCA_S_HEAP_MARKER)
221 #endif
222 #else
223 #undef _malloca
224 #define _malloca(size) \
225 __pragma(warning(suppress: 6255)) \
226 ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
227 _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE), _ALLOCA_S_STACK_MARKER) : \
228 _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE), _ALLOCA_S_HEAP_MARKER))
229 #endif
230
231 #undef _FREEA_INLINE
232 #define _FREEA_INLINE
233
234 #ifdef _FREEA_INLINE
235 /* _freea must be in the header so that its allocator matches _malloca */
236 #if !defined(__midl) && !defined(RC_INVOKED)
237 #undef _freea
238 _CRTNOALIAS __inline void __CRTDECL _freea(_Inout_opt_ void * _Memory)
239 {
240 unsigned int _Marker;
241 if (_Memory)
242 {
243 _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
244 _Marker = *(unsigned int *)_Memory;
245 if (_Marker == _ALLOCA_S_HEAP_MARKER)
246 {
247 free(_Memory);
248 }
249 #if defined(_ASSERTE)
250 else if (_Marker != _ALLOCA_S_STACK_MARKER)
251 {
252 _ASSERTE(("Corrupted pointer passed to _freea", 0));
253 }
254 #endif
255 }
256 }
257 #endif
258 #endif
259
260 #if !__STDC__
261 /* Non-ANSI names for compatibility */
262 #define alloca _alloca
263 #endif /* __STDC__*/
264
265 #endif /* _POSIX_ */
266
267 #ifdef HEAPHOOK
268 #ifndef _HEAPHOOK_DEFINED
269 /* hook function type */
270 typedef int (__cdecl * _HEAPHOOK)(int, size_t, void *, void **);
271 #define _HEAPHOOK_DEFINED
272 #endif /* _HEAPHOOK_DEFINED */
273
274 /* set hook function */
275 _CRTIMP _HEAPHOOK __cdecl _setheaphook(_In_opt_ _HEAPHOOK _NewHook);
276
277 /* hook function must handle these types */
278 #define _HEAP_MALLOC 1
279 #define _HEAP_CALLOC 2
280 #define _HEAP_FREE 3
281 #define _HEAP_REALLOC 4
282 #define _HEAP_MSIZE 5
283 #define _HEAP_EXPAND 6
284 #endif /* HEAPHOOK */
285
286
287 #ifdef __cplusplus
288 }
289 #endif
290
291 #ifdef _MSC_VER
292 #pragma pack(pop)
293 #endif /* _MSC_VER */
294
帖子浏览
|
用户名:agaric 用户ID:103 用户级别:14版主 注册时间:2008-07-30 论坛分数:13265 |
test
|
本主题讨论树
回复本帖
请先 登录,再回复本帖。