ReactOS 0.4.15-dev-7906-g1b85a5f
__node_alloc_impl Class Reference

Static Public Member Functions

static void_M_allocate (size_t &__n)
 
static void _M_deallocate (void *__p, size_t __n)
 

Private Types

typedef _Node_alloc_obj _Obj
 
typedef _Obj *_STLP_VOLATILE _Freelist
 
typedef _Obj_ChunkList
 

Static Private Member Functions

static size_t _STLP_CALL _S_round_up (size_t __bytes)
 
static _Obj_S_refill (size_t __n)
 
static char_S_chunk_alloc (size_t __p_size, int &__nobjs)
 

Static Private Attributes

static _Freelist _S_free_list [_STLP_NFREELISTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 
static size_t _S_heap_size = 0
 
static char_S_start_free = 0
 
static char_S_end_free = 0
 

Detailed Description

Definition at line 246 of file allocators.cpp.

Member Typedef Documentation

◆ _ChunkList

Definition at line 263 of file allocators.cpp.

◆ _Freelist

Definition at line 262 of file allocators.cpp.

◆ _Obj

Definition at line 261 of file allocators.cpp.

Member Function Documentation

◆ _M_allocate()

void * __node_alloc_impl::_M_allocate ( size_t __n)
static

Definition at line 318 of file allocators.cpp.

318 {
320 _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
321 _Obj *__r;
322
323 // Acquire the lock here with a constructor call.
324 // This ensures that it is released in exit or during stack
325 // unwinding.
326 _Node_Alloc_Lock __lock_instance;
327
328 if ( (__r = *__my_free_list) != 0 ) {
329 *__my_free_list = __r->_M_next;
330 } else {
331 __r = _S_refill(__n);
332 }
333# if defined (_STLP_DO_CLEAN_NODE_ALLOC)
334 _S_alloc_call();
335# endif
336 // lock is released here
337 return __r;
338}
return __n
Definition: _algo.h:75
#define _S_FREELIST_INDEX(__bytes)
Definition: allocators.cpp:120
static size_t _STLP_CALL _S_round_up(size_t __bytes)
Definition: allocators.cpp:247
static _Obj * _S_refill(size_t __n)
Definition: allocators.cpp:434
static _Freelist _S_free_list[_STLP_NFREELISTS]
Definition: allocators.cpp:273
_Node_alloc_obj _Obj
Definition: allocators.cpp:261
#define _STLP_VOLATILE
Definition: features.h:277

Referenced by __node_alloc::_M_allocate().

◆ _M_deallocate()

void __node_alloc_impl::_M_deallocate ( void __p,
size_t  __n 
)
static

Definition at line 340 of file allocators.cpp.

340 {
341 _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
342 _Obj * __pobj = __STATIC_CAST(_Obj*, __p);
343
344 // acquire lock
345 _Node_Alloc_Lock __lock_instance;
346 __pobj->_M_next = *__my_free_list;
347 *__my_free_list = __pobj;
348
349# if defined (_STLP_DO_CLEAN_NODE_ALLOC)
350 _S_dealloc_call();
351# endif
352 // lock is released here
353}
#define __STATIC_CAST(__x, __y)
Definition: features.h:585

Referenced by __node_alloc::_M_deallocate().

◆ _S_chunk_alloc()

char * __node_alloc_impl::_S_chunk_alloc ( size_t  __p_size,
int __nobjs 
)
staticprivate

Definition at line 365 of file allocators.cpp.

365 {
366 char* __result;
367 size_t __total_bytes = _p_size * __nobjs;
368 size_t __bytes_left = _S_end_free - _S_start_free;
369
370 if (__bytes_left > 0) {
371 if (__bytes_left >= __total_bytes) {
372 __result = _S_start_free;
373 _S_start_free += __total_bytes;
374 return __result;
375 }
376
377 if (__bytes_left >= _p_size) {
378 __nobjs = (int)(__bytes_left / _p_size);
379 __total_bytes = _p_size * __nobjs;
380 __result = _S_start_free;
381 _S_start_free += __total_bytes;
382 return __result;
383 }
384
385 // Try to make use of the left-over piece.
386 _Obj* _STLP_VOLATILE* __my_free_list = _S_free_list + _S_FREELIST_INDEX(__bytes_left);
387 __REINTERPRET_CAST(_Obj*, _S_start_free)->_M_next = *__my_free_list;
388 *__my_free_list = __REINTERPRET_CAST(_Obj*, _S_start_free);
390 }
391
392 size_t __bytes_to_get = 2 * __total_bytes + _S_round_up(_S_heap_size) + _STLP_OFFSET;
393
394 _STLP_TRY {
395 _S_start_free = __stlp_new_chunk(__bytes_to_get);
396 }
397#if defined (_STLP_USE_EXCEPTIONS)
398 catch (const _STLP_STD::bad_alloc&) {
399 _Obj* _STLP_VOLATILE* __my_free_list;
400 _Obj* __p;
401 // Try to do with what we have. That can't hurt.
402 // We do not try smaller requests, since that tends
403 // to result in disaster on multi-process machines.
404 for (size_t __i = _p_size; __i <= (size_t)_MAX_BYTES; __i += (size_t)_ALIGN) {
405 __my_free_list = _S_free_list + _S_FREELIST_INDEX(__i);
406 __p = *__my_free_list;
407 if (0 != __p) {
408 *__my_free_list = __p -> _M_next;
409 _S_start_free = __REINTERPRET_CAST(char*, __p);
411 return _S_chunk_alloc(_p_size, __nobjs);
412 // Any leftover piece will eventually make it to the
413 // right free list.
414 }
415 }
416 __bytes_to_get = __total_bytes + _STLP_OFFSET;
417 _S_start_free = __stlp_new_chunk(__bytes_to_get);
418 }
419#endif
420
421 _S_heap_size += __bytes_to_get >> 4;
422# if defined (_STLP_DO_CLEAN_NODE_ALLOC)
423 __REINTERPRET_CAST(_Obj*, _S_start_free)->_M_next = _S_chunks;
425# endif
426 _S_end_free = _S_start_free + __bytes_to_get;
428 return _S_chunk_alloc(_p_size, __nobjs);
429}
@ _MAX_BYTES
Definition: _alloc.h:141
@ _ALIGN
Definition: allocators.cpp:117
#define _STLP_OFFSET
Definition: allocators.cpp:358
char * __stlp_new_chunk(size_t __bytes)
Definition: allocators.cpp:78
static char * _S_start_free
Definition: allocators.cpp:286
static char * _S_end_free
Definition: allocators.cpp:288
static char * _S_chunk_alloc(size_t __p_size, int &__nobjs)
Definition: allocators.cpp:365
static size_t _S_heap_size
Definition: allocators.cpp:278
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
__kernel_size_t size_t
Definition: linux.h:237
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586
#define _STLP_TRY
Definition: features.h:817

Referenced by _S_chunk_alloc(), and _S_refill().

◆ _S_refill()

_Node_alloc_obj * __node_alloc_impl::_S_refill ( size_t  __n)
staticprivate

Definition at line 434 of file allocators.cpp.

434 {
435 int __nobjs = 20;
436 char* __chunk = _S_chunk_alloc(__n, __nobjs);
437
438 if (1 == __nobjs) return __REINTERPRET_CAST(_Obj*, __chunk);
439
441 _Obj* __result;
442 _Obj* __current_obj;
443 _Obj* __next_obj;
444
445 /* Build free list in chunk */
446 __result = __REINTERPRET_CAST(_Obj*, __chunk);
447 *__my_free_list = __next_obj = __REINTERPRET_CAST(_Obj*, __chunk + __n);
448 for (--__nobjs; --__nobjs; ) {
449 __current_obj = __next_obj;
450 __next_obj = __REINTERPRET_CAST(_Obj*, __REINTERPRET_CAST(char*, __next_obj) + __n);
451 __current_obj->_M_next = __next_obj;
452 }
453 __next_obj->_M_next = 0;
454 return __result;
455}

Referenced by _M_allocate().

◆ _S_round_up()

static size_t _STLP_CALL __node_alloc_impl::_S_round_up ( size_t  __bytes)
inlinestaticprivate

Definition at line 247 of file allocators.cpp.

248 { return (((__bytes) + (size_t)_ALIGN-1) & ~((size_t)_ALIGN - 1)); }

Referenced by _M_allocate(), and _S_chunk_alloc().

Member Data Documentation

◆ _S_end_free

char * __node_alloc_impl::_S_end_free = 0
staticprivate

Definition at line 288 of file allocators.cpp.

Referenced by _S_chunk_alloc().

◆ _S_free_list

_Node_alloc_obj *_STLP_VOLATILE __node_alloc_impl::_S_free_list = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
staticprivate

Definition at line 273 of file allocators.cpp.

Referenced by _M_allocate(), _M_deallocate(), _S_chunk_alloc(), and _S_refill().

◆ _S_heap_size

size_t __node_alloc_impl::_S_heap_size = 0
staticprivate

Definition at line 278 of file allocators.cpp.

Referenced by _S_chunk_alloc().

◆ _S_start_free

char * __node_alloc_impl::_S_start_free = 0
staticprivate

Definition at line 286 of file allocators.cpp.

Referenced by _S_chunk_alloc().


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