ReactOS  0.4.13-dev-563-g0561610
nc_alloc.cpp File Reference
#include "nc_alloc.h"
#include <string>
#include <new>
#include <cassert>
#include <cstdlib>
#include <iostream>
Include dependency graph for nc_alloc.cpp:

Go to the source code of this file.

Classes

struct  hash_void
 
class  FastAllocator
 
struct  FastAllocator::Block
 

Typedefs

typedef EH_STD::hash_set< void *, ::hash_void, EH_STD::equal_to< void * > > allocation_set
 

Functions

static allocation_setalloc_set ()
 
charAllocateBlock (size_t s)
 
static voidOperatorNew (size_t s)
 
void *_STLP_CALL operator new (size_t s)
 
void *_STLP_CALL operator new[] (size_t size) throw (EH_STD::bad_alloc)
 
void _STLP_CALL operator delete[] (void *ptr) throw ()
 
void _STLP_CALL operator delete (void *s)
 
void _STLP_CALL operator delete (void *s, uintptr_t)
 

Variables

long alloc_count = 0
 
long object_count = 0
 
TestController gTestController
 
static bool using_alloc_set = false
 
static FastAllocator gFastAllocator
 

Typedef Documentation

◆ allocation_set

typedef EH_STD::hash_set<void*, ::hash_void, EH_STD::equal_to<void*> > allocation_set

Definition at line 95 of file nc_alloc.cpp.

Function Documentation

◆ alloc_set()

static allocation_set& alloc_set ( )
static

Definition at line 98 of file nc_alloc.cpp.

98  {
99  static allocation_set s;
100  return s;
101 }
GLdouble s
Definition: gl.h:2039
EH_STD::hash_set< void *, ::hash_void, EH_STD::equal_to< void * > > allocation_set
Definition: nc_alloc.cpp:95

Referenced by TestController::ClearAllocationSet(), operator delete(), OperatorNew(), and TestController::ReportLeaked().

◆ AllocateBlock()

char* AllocateBlock ( size_t  s)
inline

Definition at line 173 of file nc_alloc.cpp.

173  {
174 #if !defined (NO_FAST_ALLOCATOR)
175  char * const p = (char*)gFastAllocator.Allocate( s );
176  if (p != 0)
177  return p;
178 #endif
179 
180  return (char*)EH_CSTD::malloc(s);
181 }
static void * Allocate(size_t s)
Definition: nc_alloc.cpp:115
GLdouble s
Definition: gl.h:2039
static FastAllocator gFastAllocator
Definition: nc_alloc.cpp:170
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by OperatorNew().

◆ operator delete() [1/2]

Definition at line 245 of file nc_alloc.cpp.

247 {
248  if ( s != 0 ) {
249  if ( !using_alloc_set ) {
250  --alloc_count;
251 
253  using_alloc_set = true;
254  allocation_set::iterator p = alloc_set().find( (char*)s );
255  EH_ASSERT( p != alloc_set().end() );
256  alloc_set().erase( p );
257  using_alloc_set = false;
258  }
259  }
260 # if ! defined (NO_FAST_ALLOCATOR)
261  if ( !gFastAllocator.Free( s ) )
262 # endif
263  EH_CSTD::free(s);
264  }
265 }
static bool using_alloc_set
Definition: nc_alloc.cpp:104
TestController gTestController
Definition: nc_alloc.cpp:46
#define free
Definition: debug_ros.c:5
GLuint GLuint end
Definition: gl.h:1545
static bool LeakDetectionEnabled()
Definition: nc_alloc.h:154
static bool TrackingEnabled()
Definition: nc_alloc.h:134
static allocation_set & alloc_set()
Definition: nc_alloc.cpp:98
long alloc_count
Definition: nc_alloc.cpp:36
#define EH_ASSERT
Definition: Prefix.h:37
GLdouble s
Definition: gl.h:2039
static FastAllocator gFastAllocator
Definition: nc_alloc.cpp:170
static bool Free(void *p)
Definition: nc_alloc.cpp:130
GLfloat GLfloat p
Definition: glext.h:8902

◆ operator delete() [2/2]

Definition at line 270 of file nc_alloc.cpp.

272 {
273  ::operator delete(s);
274 }
operator
GLdouble s
Definition: gl.h:2039

◆ operator delete[]()

void _STLP_CALL operator delete[] ( void ptr)
throw (
)

Definition at line 238 of file nc_alloc.cpp.

239 { operator delete( ptr ); }
static PVOID ptr
Definition: dispmode.c:27

◆ operator new()

Definition at line 205 of file nc_alloc.cpp.

209 { return OperatorNew( s ); }
GLdouble s
Definition: gl.h:2039
static void * OperatorNew(size_t s)
Definition: nc_alloc.cpp:183

◆ operator new[]()

void* _STLP_CALL operator new[] ( size_t  size)
throw (EH_STD::bad_alloc
)

Definition at line 223 of file nc_alloc.cpp.

223  {
224  return OperatorNew( size );
225 }
GLsizeiptr size
Definition: glext.h:5919
static void * OperatorNew(size_t s)
Definition: nc_alloc.cpp:183

◆ OperatorNew()

static void* OperatorNew ( size_t  s)
static

Definition at line 183 of file nc_alloc.cpp.

183  {
184  if (!using_alloc_set) {
186  ++alloc_count;
187  }
188 
189  char *p = AllocateBlock(s);
190 
193  !using_alloc_set) {
194  using_alloc_set = true;
195  bool inserted = alloc_set().insert(p).second;
196  // Suppress warning about unused variable.
197  inserted;
198  EH_ASSERT(inserted);
199  using_alloc_set = false;
200  }
201 
202  return p;
203 }
static bool using_alloc_set
Definition: nc_alloc.cpp:104
TestController gTestController
Definition: nc_alloc.cpp:46
static bool LeakDetectionEnabled()
Definition: nc_alloc.h:154
static bool TrackingEnabled()
Definition: nc_alloc.h:134
static allocation_set & alloc_set()
Definition: nc_alloc.cpp:98
long alloc_count
Definition: nc_alloc.cpp:36
#define EH_ASSERT
Definition: Prefix.h:37
GLdouble s
Definition: gl.h:2039
void simulate_possible_failure()
Definition: nc_alloc.h:117
GLfloat GLfloat p
Definition: glext.h:8902
char * AllocateBlock(size_t s)
Definition: nc_alloc.cpp:173

Referenced by operator new(), and operator new[]().

Variable Documentation

◆ alloc_count

◆ gFastAllocator

FastAllocator gFastAllocator
static

Definition at line 170 of file nc_alloc.cpp.

Referenced by AllocateBlock(), and operator delete().

◆ gTestController

TestController gTestController

Definition at line 46 of file nc_alloc.cpp.

Referenced by assert_sorted_version(), ConstCheck(), main(), operator delete(), test_assign_op< T >::operator()(), test_push_back< C >::operator()(), test_copy_construct< T >::operator()(), test_construct_iter_range_n< T >::operator()(), test_list_sort::operator()(), test_stable_partition::operator()(), test_construct_pointer_range< T >::operator()(), test_construct_iter_range< T >::operator()(), test_insert_one< C >::operator()(), test_insert_n< C >::operator()(), test_insert_value< C >::operator()(), test_insert_noresize< C >::operator()(), test_insert_range< C, Iter >::operator()(), OperatorNew(), simulate_constructor(), simulate_possible_failure(), StrongCheck(), test_assign_op< T >::test_assign_op(), test_BitVector_reserve::test_BitVector_reserve(), test_construct_iter_range< T >::test_construct_iter_range(), test_construct_iter_range_n< T >::test_construct_iter_range_n(), test_construct_n< T >::test_construct_n(), test_construct_n_instance< T >::test_construct_n_instance(), test_construct_pointer_range< T >::test_construct_pointer_range(), test_copy_construct< T >::test_copy_construct(), test_default_construct< T >::test_default_construct(), test_hash_resize< T >::test_hash_resize(), test_inplace_merge_1::test_inplace_merge_1(), test_inplace_merge_2::test_inplace_merge_2(), test_insert_n< C >::test_insert_n(), test_insert_noresize< C >::test_insert_noresize(), test_insert_one< C >::test_insert_one(), test_insert_range< C, Iter >::test_insert_range(), test_insert_value< C >::test_insert_value(), test_list_sort::test_list_sort(), test_push_back< C >::test_push_back(), test_push_front< C >::test_push_front(), test_reserve::test_reserve(), test_slist_sort::test_slist_sort(), test_stable_partition::test_stable_partition(), test_stable_sort_1::test_stable_sort_1(), test_stable_sort_2::test_stable_sort_2(), test_uninitialized_copy::test_uninitialized_copy(), test_uninitialized_fill::test_uninitialized_fill(), test_uninitialized_fill_n::test_uninitialized_fill_n(), and WeakCheck().

◆ object_count

◆ using_alloc_set

bool using_alloc_set = false
static