Commit 64be2eb634655a0ac1af1c1cf1a8f8a00752125d
- Diff rendering mode:
- inline
- side by side
stlport/stl/_alloc.h
(38 / 19)
|   | |||
| 397 | 397 | }; | |
| 398 | 398 | ||
| 399 | 399 | #if defined (_STLP_USE_PERTHREAD_ALLOC) | |
| 400 | |||
| 401 | 400 | _STLP_END_NAMESPACE | |
| 402 | // include additional header here | ||
| 403 | 401 | # include <stl/_pthread_alloc.h> | |
| 404 | 402 | _STLP_BEGIN_NAMESPACE | |
| 405 | |||
| 406 | typedef __pthread_alloc __alloc_type; | ||
| 407 | #elif defined (_STLP_USE_NEWALLOC) | ||
| 408 | typedef __new_alloc __alloc_type; | ||
| 409 | #elif defined (_STLP_USE_MALLOC) | ||
| 410 | typedef __malloc_alloc __alloc_type; | ||
| 411 | #else | ||
| 412 | typedef __node_alloc __alloc_type; | ||
| 413 | 403 | #endif | |
| 414 | 404 | ||
| 415 | #if defined (_STLP_DEBUG_ALLOC) | ||
| 416 | typedef __debug_alloc<__alloc_type> __sgi_alloc; | ||
| 417 | #else | ||
| 418 | typedef __alloc_type __sgi_alloc; | ||
| 419 | #endif | ||
| 420 | |||
| 421 | 405 | // This implements allocators as specified in the C++ standard. | |
| 422 | 406 | // | |
| 423 | 407 | // Note that standard-conforming allocators use many language features | |
| … | … | ||
| 413 | 413 | template <class _Tp> | |
| 414 | 414 | class allocator | |
| 415 | 415 | { | |
| 416 | private: | ||
| 417 | // underlying allocator implementation | ||
| 418 | #if defined (_STLP_USE_PERTHREAD_ALLOC) | ||
| 419 | #ifdef _STLP_DEBUG_ALLOC | ||
| 420 | typedef __debug_alloc<__pthread_alloc> __alloc_type; | ||
| 421 | #else | ||
| 422 | typedef __pthread_alloc __alloc_type; | ||
| 423 | #endif | ||
| 424 | |||
| 425 | #elif defined (_STLP_USE_NEWALLOC) | ||
| 426 | |||
| 427 | #ifdef _STLP_DEBUG_ALLOC | ||
| 428 | typedef __debug_alloc<__new_alloc> __alloc_type; | ||
| 429 | #else | ||
| 430 | typedef __new_alloc __alloc_type; | ||
| 431 | #endif | ||
| 432 | |||
| 433 | #elif defined (_STLP_USE_MALLOC) | ||
| 434 | |||
| 435 | #ifdef _STLP_DEBUG_ALLOC | ||
| 436 | typedef __debug_alloc<__malloc_alloc> __alloc_type; | ||
| 437 | #else | ||
| 438 | typedef __malloc_alloc __alloc_type; | ||
| 439 | #endif | ||
| 440 | |||
| 441 | #else // then use __node_alloc | ||
| 442 | |||
| 443 | #ifdef _STLP_DEBUG_ALLOC | ||
| 444 | typedef __debug_alloc<__node_alloc> __alloc_type; | ||
| 445 | #else | ||
| 446 | typedef __node_alloc __alloc_type; | ||
| 447 | #endif | ||
| 448 | |||
| 449 | #endif | ||
| 450 | |||
| 416 | 451 | public: | |
| 417 | 452 | typedef _Tp value_type; | |
| 418 | 453 | typedef _Tp* pointer; | |
| … | … | ||
| 488 | 488 | } | |
| 489 | 489 | if (__n != 0) { | |
| 490 | 490 | size_type __buf_size = __n * sizeof(value_type); | |
| 491 | _Tp* __ret = __REINTERPRET_CAST(_Tp*, __sgi_alloc::allocate(__buf_size)); | ||
| 491 | _Tp* __ret = __REINTERPRET_CAST(_Tp*, __alloc_type::allocate(__buf_size)); | ||
| 492 | 492 | #if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC) | |
| 493 | 493 | memset((char*)__ret, _STLP_SHRED_BYTE, __buf_size); | |
| 494 | 494 | #endif | |
| … | … | ||
| 506 | 506 | #if defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_DEBUG_ALLOC) | |
| 507 | 507 | memset((char*)__p, _STLP_SHRED_BYTE, __n * sizeof(value_type)); | |
| 508 | 508 | #endif | |
| 509 | __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type)); | ||
| 509 | __alloc_type::deallocate((void*)__p, __n * sizeof(value_type)); | ||
| 510 | 510 | } | |
| 511 | 511 | } | |
| 512 | 512 | #if !defined (_STLP_NO_ANACHRONISMS) | |
| … | … | ||
| 514 | 514 | void deallocate(pointer __p) const | |
| 515 | 515 | { | |
| 516 | 516 | if (__p != 0) | |
| 517 | __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); | ||
| 517 | __alloc_type::deallocate((void*)__p, sizeof(value_type)); | ||
| 518 | 518 | } | |
| 519 | 519 | #endif | |
| 520 | 520 |

