ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_alloc.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1996,1997
00004  * Silicon Graphics Computer Systems, Inc.
00005  *
00006  * Copyright (c) 1997
00007  * Moscow Center for SPARC Technology
00008  *
00009  * Copyright (c) 1999
00010  * Boris Fomitchev
00011  *
00012  * This material is provided "as is", with absolutely no warranty expressed
00013  * or implied. Any use is at your own risk.
00014  *
00015  * Permission to use or copy this software for any purpose is hereby granted
00016  * without fee, provided the above notices are retained on all copies.
00017  * Permission to modify the code and to distribute modified code is granted,
00018  * provided the above notices are retained, and a notice that the code was
00019  * modified is included with the above copyright notice.
00020  *
00021  */
00022 #ifndef _STLP_ALLOC_C
00023 #define _STLP_ALLOC_C
00024 
00025 #ifndef _STLP_INTERNAL_ALLOC_H
00026 #  include <stl/_alloc.h>
00027 #endif
00028 
00029 #if defined (__WATCOMC__)
00030 #  pragma warning 13 9
00031 #  pragma warning 367 9
00032 #  pragma warning 368 9
00033 #endif
00034 
00035 _STLP_BEGIN_NAMESPACE
00036 
00037 template <class _Alloc>
00038 void * _STLP_CALL __debug_alloc<_Alloc>::allocate(size_t __n) {
00039   size_t __total_extra = __extra_before_chunk() + __extra_after_chunk();
00040   size_t __real_n = __n + __total_extra;
00041   if (__real_n < __n) {
00042     //It means that we rolled on size_t, __n must be very large:
00043     _STLP_THROW_BAD_ALLOC;
00044   }
00045   __alloc_header *__result = (__alloc_header *)__allocator_type::allocate(__real_n);
00046   memset((char*)__result, __shred_byte, __real_n * sizeof(value_type));
00047   __result->__magic = __magic;
00048   __result->__type_size = sizeof(value_type);
00049   __result->_M_size = (_STLP_UINT32_T)__n;
00050   return ((char*)__result) + (long)__extra_before;
00051 }
00052 
00053 template <class _Alloc>
00054 void  _STLP_CALL
00055 __debug_alloc<_Alloc>::deallocate(void *__p, size_t __n) {
00056   __alloc_header * __real_p = (__alloc_header*)((char *)__p -(long)__extra_before);
00057   // check integrity
00058   _STLP_VERBOSE_ASSERT(__real_p->__magic != __deleted_magic, _StlMsg_DBA_DELETED_TWICE)
00059   _STLP_VERBOSE_ASSERT(__real_p->__magic == __magic, _StlMsg_DBA_NEVER_ALLOCATED)
00060   _STLP_VERBOSE_ASSERT(__real_p->__type_size == 1,_StlMsg_DBA_TYPE_MISMATCH)
00061   _STLP_VERBOSE_ASSERT(__real_p->_M_size == __n, _StlMsg_DBA_SIZE_MISMATCH)
00062   // check pads on both sides
00063   unsigned char* __tmp;
00064   for (__tmp = (unsigned char*)(__real_p + 1); __tmp < (unsigned char*)__p; ++__tmp) {
00065     _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_UNDERRUN)
00066   }
00067 
00068   size_t __real_n = __n + __extra_before_chunk() + __extra_after_chunk();
00069 
00070   for (__tmp= ((unsigned char*)__p) + __n * sizeof(value_type);
00071        __tmp < ((unsigned char*)__real_p) + __real_n ; ++__tmp) {
00072     _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_OVERRUN)
00073   }
00074 
00075   // that may be unfortunate, just in case
00076   __real_p->__magic = __deleted_magic;
00077   memset((char*)__p, __shred_byte, __n * sizeof(value_type));
00078   __allocator_type::deallocate(__real_p, __real_n);
00079 }
00080 
00081 _STLP_END_NAMESPACE
00082 
00083 #endif /*  _STLP_ALLOC_C */
00084 
00085 // Local Variables:
00086 // mode:C++
00087 // End:

Generated on Fri May 25 2012 04:27:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.