--- parser3/src/include/pa_array.h 2003/02/17 09:56:15 1.57.2.22 +++ parser3/src/include/pa_array.h 2003/02/26 10:17:30 1.57.2.26 @@ -8,17 +8,18 @@ #ifndef PA_ARRAY_H #define PA_ARRAY_H -static const char* IDENT_ARRAY_Y="$Date: 2003/02/17 09:56:15 $"; +static const char* IDENT_ARRAY_H="$Date: 2003/02/26 10:17:30 $"; -#include "pa_pool.h" +// includes + +#include "pa_memory.h" #include "pa_exception.h" -template class Array_iterator; +// forwards -/** - Simple Array. +template class Array_iterator; -*/ +/// Simple Array template class Array: public PA_Object { friend class Array_iterator; @@ -50,9 +51,12 @@ public: Exception::undefined_source, "Array::Array(%d, %d) too small", initial, delta); + // we can't use new(0) here[like we did in Hash] because we need to use realloc + // on MSVC new returns NOT pointer learned from pa_malloc, so we can't do new+realloc felements=static_cast(calloc(fallocated*sizeof(T))); } override ~Array() { + // see comment in ctor T *last=felements+fused; for(T *current=felements; current~T(); // manually invoking destructors @@ -74,11 +78,11 @@ public: /// append other Array portion to this one. starting from offset Array& append(const Array& src, int offset=0, int limit=0) { - if(!(offset>=0 && offset0) - expand(needed); - - memcpy(&felements[fused+=limit], &src.felements[offset], limit*sizeof(T)); + int delta=limit-(fallocated-fused); + if(delta>0) + expand(delta); + + T* from=&src.felements[offset]; + T* to=&felements[fused]; + T* from_end=from+limit; + while(from CharPtr; - -/** - Pool mechanizm allows users not to free up allocated memory, - leaving that problem to 'pools'. -*/ -class Pool: public Array { -public: - char *malloc(size_t size) { - CharPtr result=CharPtr((char *)Array::malloc(size)); - *this += result; - return result.get(); - } - - char *copy(const char* buf, size_t size=0) { - if(!size) - size=strlen(buf)+1; - - char *result=malloc(size); - memcpy(result, buf, size); - return result; - } -}; - -inline void *operator new[] (size_t size, Pool& pool) { - return pool.malloc(size); -} /// handy array iterator template class Array_iterator {