--- parser3/src/include/pa_array.h 2003/01/29 13:52:21 1.57.2.14 +++ parser3/src/include/pa_array.h 2003/02/17 11:29:53 1.57.2.23 @@ -1,14 +1,14 @@ /** @file Parser: Array & Array_iterator classes decls. - Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_ARRAY_H #define PA_ARRAY_H -static const char* IDENT_ARRAY_Y="$Date: 2003/01/29 13:52:21 $"; +static const char* IDENT_ARRAY_Y="$Date: 2003/02/17 11:29:53 $"; #include "pa_pool.h" #include "pa_exception.h" @@ -50,14 +50,14 @@ public: Exception::undefined_source, "Array::Array(%d, %d) too small", initial, delta); - felements=new T[fallocated]; + felements=static_cast(calloc(fallocated*sizeof(T))); } override ~Array() { T *last=felements+fused; for(T *current=felements; current~T(); // manually invoking destructors - delete felements; + free(felements); } /// how many items are in Array @@ -89,30 +89,36 @@ public: limit=m; } - int needed=limit-(fallocated-fused); - if(needed>0) - 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=0 && index=0 && index 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) { @@ -165,7 +176,7 @@ public: return result.get(); } - char *copy(const char *buf, size_t size=0) { + char *copy(const char* buf, size_t size=0) { if(!size) size=strlen(buf)+1; @@ -175,7 +186,7 @@ public: } }; -inline void *operator new(size_t size, Pool& pool) { +inline void *operator new[] (size_t size, Pool& pool) { return pool.malloc(size); } @@ -199,7 +210,7 @@ public: } /// quickly extracts next Array element - T next() { + T& next() { return *(fcurrent++); }