diff -u -r1.1.1.1 -r1.8 --- stlport/stl/_alloc.c 2001/09/12 03:20:11 1.1.1.1 +++ stlport/stl/_alloc.c 2001/11/15 07:41:41 1.8 @@ -53,6 +53,17 @@ # define _STLP_CHUNK_MALLOC(s) __stl_new(s) # endif #endif // !_DEBUG +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) +# if defined(_STLP_MSVC) && (_STLP_MSVC>=1020 && defined(_STLP_DEBUG_ALLOC)) && ! defined (_STLP_WINCE) +# define _STLP_CHUNK_FREE(p) free(p) +# else // !_STLP_NODE_ALLOC_USE_CHUNK_CLEANER +# ifdef _STLP_NODE_ALLOC_USE_MALLOC +# define _STLP_CHUNK_FREE(p) _STLP_VENDOR_CSTD::free(p) +# else +# define _STLP_CHUNK_FREE(p) __stl_delete(p) +# endif +# endif // !_STLP_NODE_ALLOC_USE_CHUNK_CLEANER +#endif #define _S_FREELIST_INDEX(__bytes) ((__bytes-size_t(1))>>(int)_ALIGN_SHIFT) @@ -181,6 +192,41 @@ // lock is released here } +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) +template +class _Node_Chunk { +private: + _Node_Chunk *__prev; + static _Node_Chunk *_S_chunk_link; +public: + void *operator new(size_t __size, void *__p) {return __p;} + void operator delete(void *__p) {_STLP_CHUNK_FREE(__p);} + _Node_Chunk() { + __prev = _S_chunk_link; + _S_chunk_link = this; + } + ~_Node_Chunk() { + if (__prev) + delete __prev; + } + static char *_S_alloc(size_t __size) { + _Node_Chunk *p = + new((void *)_STLP_CHUNK_MALLOC(__size + sizeof(_Node_Chunk))) _Node_Chunk; + return (char *)(p + 1); + } + static void _S_clean(void) { + if (_S_chunk_link) + delete _S_chunk_link; + _S_chunk_link = 0; + memset(__node_alloc<__threads, __inst>::_S_free_list, 0, + sizeof(__node_alloc<__threads, __inst>::_S_free_list)); + __node_alloc<__threads, __inst>::_S_start_free = 0; + __node_alloc<__threads, __inst>::_S_end_free = 0; + __node_alloc<__threads, __inst>::_S_heap_size = 0; + } +}; +#endif + /* We allocate memory in large chunks in order to avoid fragmenting */ /* the malloc heap too much. */ /* We assume that size is properly aligned. */ @@ -215,7 +261,11 @@ ((_Obj*)_S_start_free) -> _M_free_list_link = *__my_free_list; *__my_free_list = (_Obj*)_S_start_free; } +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) + _S_start_free = _Node_Chunk<__threads, __inst>::_S_alloc(__bytes_to_get); +#else _S_start_free = (char*)_STLP_CHUNK_MALLOC(__bytes_to_get); +#endif if (0 == _S_start_free) { size_t __i; _Obj* _STLP_VOLATILE* __my_free_list; @@ -236,7 +286,11 @@ } } _S_end_free = 0; // In case of exception. +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) + _S_start_free = _Node_Chunk<__threads, __inst>::_S_alloc(__bytes_to_get); +#else _S_start_free = (char*)_STLP_CHUNK_MALLOC(__bytes_to_get); +#endif /* (char*)malloc_alloc::allocate(__bytes_to_get); */ @@ -306,7 +360,12 @@ // compiler happy. Otherwise it appears to allocate too little // space for the array. +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) template +_Node_Chunk<__threads, __inst> *_Node_Chunk<__threads, __inst>::_S_chunk_link = 0; +#endif + +template char *__node_alloc<__threads, __inst>::_S_start_free = 0; template @@ -337,6 +396,14 @@ __DECLARE_INSTANCE(_Node_alloc_obj * _STLP_VOLATILE, _STLP_ALLOC_THREADS::_S_free_list[_STLP_NFREELISTS], ={0}); + +#if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) +# define _STLP_ALLOC_NOTHREADS_NODECHUNK _Node_Chunk +# define _STLP_ALLOC_THREADS_NODECHUNK _Node_Chunk +__DECLARE_INSTANCE(_STLP_ALLOC_NOTHREADS_NODECHUNK *, _STLP_ALLOC_NOTHREADS_NODECHUNK::_S_chunk_link ,=0); +__DECLARE_INSTANCE(_STLP_ALLOC_THREADS_NODECHUNK *, _STLP_ALLOC_THREADS_NODECHUNK::_S_chunk_link ,=0); +#endif + // # ifdef _STLP_THREADS __DECLARE_INSTANCE(_STLP_STATIC_MUTEX, _STLP_ALLOC_NOTHREADS_LOCK::_S_lock, diff -u -r1.1.1.1 -r1.6 --- stlport/stl/_alloc.h 2001/09/12 03:20:11 1.1.1.1 +++ stlport/stl/_alloc.h 2001/11/15 07:11:48 1.6 @@ -232,10 +232,16 @@ // if it is inconvenient to allocate the requested number. static char* _STLP_CALL _S_chunk_alloc(size_t __p_size, int& __nobjs); // Chunk allocation state. +# if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) +public: +# endif static _Node_alloc_obj * _STLP_VOLATILE _S_free_list[_STLP_NFREELISTS]; static char* _S_start_free; static char* _S_end_free; static size_t _S_heap_size; +# if defined(_STLP_NODE_ALLOC_USE_CHUNK_CLEANER) +private: +# endif static void * _STLP_CALL _M_allocate(size_t __n); /* __p may not be 0 */ static void _STLP_CALL _M_deallocate(void *__p, size_t __n);