ReactOS 0.4.15-dev-6047-gb29e82d
__debug_alloc< _Alloc > Class Template Reference

#include <_alloc.h>

Inheritance diagram for __debug_alloc< _Alloc >:
Collaboration diagram for __debug_alloc< _Alloc >:

Classes

struct  __alloc_header
 

Public Types

typedef _Alloc __allocator_type
 
typedef _Alloc::value_type value_type
 

Public Member Functions

 __debug_alloc ()
 
 ~__debug_alloc ()
 

Static Public Member Functions

static void *_STLP_CALL allocate (size_t)
 
static void _STLP_CALL deallocate (void *, size_t)
 

Private Types

enum  { __pad = 8 , __magic = 0xdeba , __deleted_magic = 0xdebd , __shred_byte = _STLP_SHRED_BYTE }
 
enum  { __extra_before = 16 , __extra_after = 8 }
 

Static Private Member Functions

static size_t _STLP_CALL __extra_before_chunk ()
 
static size_t _STLP_CALL __extra_after_chunk ()
 

Detailed Description

template<class _Alloc>
class __debug_alloc< _Alloc >

Definition at line 104 of file _alloc.h.

Member Typedef Documentation

◆ __allocator_type

template<class _Alloc >
typedef _Alloc __debug_alloc< _Alloc >::__allocator_type

Definition at line 106 of file _alloc.h.

◆ value_type

template<class _Alloc >
typedef _Alloc::value_type __debug_alloc< _Alloc >::value_type

Definition at line 107 of file _alloc.h.

Member Enumeration Documentation

◆ anonymous enum

template<class _Alloc >
anonymous enum
private
Enumerator
__pad 
__magic 
__deleted_magic 
__shred_byte 

Definition at line 115 of file _alloc.h.

115 { __pad = 8, __magic = 0xdeba, __deleted_magic = 0xdebd,
@ __deleted_magic
Definition: _alloc.h:115
@ __shred_byte
Definition: _alloc.h:116
#define _STLP_SHRED_BYTE
Definition: features.h:903

◆ anonymous enum

template<class _Alloc >
anonymous enum
private
Enumerator
__extra_before 
__extra_after 

Definition at line 118 of file _alloc.h.

118{ __extra_before = 16, __extra_after = 8 };
@ __extra_before
Definition: _alloc.h:118
@ __extra_after
Definition: _alloc.h:118

Constructor & Destructor Documentation

◆ __debug_alloc()

template<class _Alloc >
__debug_alloc< _Alloc >::__debug_alloc ( )
inline

Definition at line 131 of file _alloc.h.

131{}

◆ ~__debug_alloc()

template<class _Alloc >
__debug_alloc< _Alloc >::~__debug_alloc ( )
inline

Definition at line 132 of file _alloc.h.

132{}

Member Function Documentation

◆ __extra_after_chunk()

template<class _Alloc >
static size_t _STLP_CALL __debug_alloc< _Alloc >::__extra_after_chunk ( )
inlinestaticprivate

Definition at line 126 of file _alloc.h.

126 {
127 return (long)__extra_after / sizeof(value_type) +
128 (size_t)((long)__extra_after % sizeof(value_type) > 0);
129 }
_Alloc::value_type value_type
Definition: _alloc.h:107
#define long
Definition: qsort.c:33

◆ __extra_before_chunk()

template<class _Alloc >
static size_t _STLP_CALL __debug_alloc< _Alloc >::__extra_before_chunk ( )
inlinestaticprivate

Definition at line 122 of file _alloc.h.

122 {
123 return (long)__extra_before / sizeof(value_type) +
124 (size_t)((long)__extra_before % sizeof(value_type) > 0);
125 }

◆ allocate()

template<class _Alloc >
_STLP_BEGIN_NAMESPACE void *_STLP_CALL __debug_alloc< _Alloc >::allocate ( size_t  __n)
static

Definition at line 38 of file _alloc.c.

38 {
39 size_t __total_extra = __extra_before_chunk() + __extra_after_chunk();
40 size_t __real_n = __n + __total_extra;
41 if (__real_n < __n) {
42 //It means that we rolled on size_t, __n must be very large:
44 }
45 __alloc_header *__result = (__alloc_header *)__allocator_type::allocate(__real_n);
46 memset((char*)__result, __shred_byte, __real_n * sizeof(value_type));
47 __result->__magic = __magic;
48 __result->__type_size = sizeof(value_type);
49 __result->_M_size = (_STLP_UINT32_T)__n;
50 return ((char*)__result) + (long)__extra_before;
51}
return __n
Definition: _algo.h:75
#define _STLP_UINT32_T
Definition: _apple.h:37
#define _STLP_THROW_BAD_ALLOC
Definition: _new.h:116
static size_t _STLP_CALL __extra_after_chunk()
Definition: _alloc.h:126
static size_t _STLP_CALL __extra_before_chunk()
Definition: _alloc.h:122
#define memset(x, y, z)
Definition: compat.h:39

◆ deallocate()

template<class _Alloc >
void _STLP_CALL __debug_alloc< _Alloc >::deallocate ( void __p,
size_t  __n 
)
static

Definition at line 55 of file _alloc.c.

55 {
56 __alloc_header * __real_p = (__alloc_header*)((char *)__p -(long)__extra_before);
57 // check integrity
58 _STLP_VERBOSE_ASSERT(__real_p->__magic != __deleted_magic, _StlMsg_DBA_DELETED_TWICE)
59 _STLP_VERBOSE_ASSERT(__real_p->__magic == __magic, _StlMsg_DBA_NEVER_ALLOCATED)
60 _STLP_VERBOSE_ASSERT(__real_p->__type_size == 1,_StlMsg_DBA_TYPE_MISMATCH)
61 _STLP_VERBOSE_ASSERT(__real_p->_M_size == __n, _StlMsg_DBA_SIZE_MISMATCH)
62 // check pads on both sides
63 unsigned char* __tmp;
64 for (__tmp = (unsigned char*)(__real_p + 1); __tmp < (unsigned char*)__p; ++__tmp) {
65 _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_UNDERRUN)
66 }
67
68 size_t __real_n = __n + __extra_before_chunk() + __extra_after_chunk();
69
70 for (__tmp= ((unsigned char*)__p) + __n * sizeof(value_type);
71 __tmp < ((unsigned char*)__real_p) + __real_n ; ++__tmp) {
72 _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_OVERRUN)
73 }
74
75 // that may be unfortunate, just in case
76 __real_p->__magic = __deleted_magic;
77 memset((char*)__p, __shred_byte, __n * sizeof(value_type));
78 __allocator_type::deallocate(__real_p, __real_n);
79}
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439

The documentation for this class was generated from the following files: