--- parser3/src/include/pa_pool.h 2001/10/19 14:42:53 1.65 +++ parser3/src/include/pa_pool.h 2001/11/16 11:51:32 1.71 @@ -3,9 +3,9 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_pool.h,v 1.65 2001/10/19 14:42:53 parser Exp $ + $Id: pa_pool.h,v 1.71 2001/11/16 11:51:32 paf Exp $ */ #ifndef PA_POOL_H @@ -14,7 +14,7 @@ #include "pa_config_includes.h" #ifdef XML -#include< memory> +#include #include #include #endif @@ -22,7 +22,6 @@ // forwards class Exception; -class Temp_exception; class String; /** @@ -38,15 +37,17 @@ public: Pool(void *astorage); ~Pool(); + ///{@ statistics + size_t total_allocated() { return ftotal_allocated; } + unsigned int total_times() { return ftotal_times; } + ///}@ + void set_context(void *acontext) { fcontext=acontext; } void *get_context() { return fcontext; } - void set_tag(void *atag) { ftag=atag; } - void *tag() { return ftag; } - /// allocates some bytes on pool - void *malloc(size_t size/*, int place=0*/) { - return check(real_malloc(size/*, place*/), size); + void *malloc(size_t size, int place=0) { + return check(real_malloc(size, place), size); } /// allocates some bytes clearing them with zeros void *calloc(size_t size) { @@ -68,14 +69,13 @@ private: void *fstorage; void *fcontext; - void *ftag; const String *charset; private: //{ /// @name implementation defined - void *real_malloc(size_t size/*, int place*/); + void *real_malloc(size_t size, int place); void *real_calloc(size_t size); bool real_register_cleanup(void (*cleanup) (void *), void *data); //} @@ -84,8 +84,11 @@ private: /// checks whether mem allocated OK. throws exception otherwise void *check(void *ptr, size_t size) { - if(ptr) + if(ptr) { + ftotal_allocated+=size; + ftotal_times++; return ptr; + } fail_alloc(size); @@ -106,7 +109,7 @@ public: /// converts Xalan string to parser String String& transcode(const XalanDOMString& s); /// converts char * to Xalan string - std::auto_ptr< XalanDOMString> transcode_buf(const char *buf, size_t buf_size); + std::auto_ptr transcode_buf(const char *buf, size_t buf_size); /// converts parser String to Xalan string std::auto_ptr transcode(const String& s); @@ -121,6 +124,11 @@ private: #endif +private: // statistics + + size_t ftotal_allocated; + unsigned int ftotal_times; + private: //disabled Pool(const Pool&); @@ -141,7 +149,7 @@ public: /// the Pooled-sole: Pooled instances can be allocated in Pool rather then on heap static void *operator new(size_t size, Pool& apool) { - return apool.malloc(size/*, 1*/); + return apool.malloc(size, 1); } Pooled(Pool& apool) : fpool(&apool) {} @@ -157,7 +165,7 @@ public: //{ /// @name useful wrapper around pool - void *malloc(size_t size) const { return fpool->malloc(size); } + void *malloc(size_t size, int place=0) const { return fpool->malloc(size, place); } void *calloc(size_t size) const { return fpool->calloc(size); } void register_cleanup(void (*cleanup) (void *), void *data) { fpool->register_cleanup(cleanup, data); } #ifdef XML