--- parser3/src/include/pa_pool.h 2002/02/08 07:27:44 1.77 +++ parser3/src/include/pa_pool.h 2003/03/18 09:53:01 1.86.4.2 @@ -1,16 +1,16 @@ /** @file Parser: pool class decl. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: pa_pool.h,v 1.77 2002/02/08 07:27:44 paf Exp $ + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_POOL_H #define PA_POOL_H +static const char* IDENT_POOL_H="$Date: 2003/03/18 09:53:01 $"; + #include "pa_config_includes.h" #ifdef XML @@ -37,16 +37,27 @@ class Pool { public: Pool(void *astorage); + ~Pool(); - ///{@ statistics + //{@ collector issues + void collect_garbage(); + void log_high_watermark(const char *msg); + //}@ + + //{@ 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; } /// allocates some bytes on pool + void *malloc_atomic(size_t size, int place=0) { + return check(real_malloc_atomic(size, place), size); + } + + /// allocates some bytes on pool void *malloc(size_t size, int place=0) { return check(real_malloc(size, place), size); } @@ -56,31 +67,46 @@ public: } /// registers a routine to clean up non-pooled allocations - void register_cleanup(void (*cleanup) (void *), void *data) { + void register_cleanup(void (*cleanup) (void *, void *), void *data) { if(!real_register_cleanup(cleanup, data)) fail_register_cleanup(); } - ///{@ source charset + //{@ helpers + void *copy(const void *buf, const size_t size); + char *copy(const char *cstr); + //}@ + + //{@ source charset void set_source_charset(Charset& acharset); Charset& get_source_charset(); - ///}@ + //}@ - ///{@ client charset + //{@ client charset void set_client_charset(Charset& charset); Charset& get_client_charset(); - ///}@ + //}@ #ifdef XML /// @see Charset::transcode_cstr(xmlChar *s); const char *transcode_cstr(xmlChar *s); /// @see Charset::transcode(xmlChar *s); - String& transcode(xmlChar *s); + String& transcode(xmlChar *s +#ifndef NO_STRING_ORIGIN + , const String *origin +#endif + ); /// @see Charset::transcode_cstr(GdomeDOMString *s); const char *transcode_cstr(GdomeDOMString *s); /// @see Charset::transcode(GdomeDOMString *s); - String& transcode(GdomeDOMString *s); + String& transcode(GdomeDOMString *s +#ifndef NO_STRING_ORIGIN + , const String *origin +#endif + ); + /// @see Charset::transcode_cstr(const char *buf, size_t buf_size=0); + xmlChar *transcode_buf2xchar(const char *buf, size_t buf_size=0); /// @see Charset::transcode(const String& s) GdomeDOMString_auto_ptr transcode(const String& s); @@ -97,9 +123,12 @@ private: //{ /// @name implementation defined + void real_init(); + void real_finit(); void *real_malloc(size_t size, int place); + void *real_malloc_atomic(size_t size, int place); void *real_calloc(size_t size); - bool real_register_cleanup(void (*cleanup) (void *), void *data); + bool real_register_cleanup(void (*cleanup) (void *,void *), void *data); //} private: @@ -141,6 +170,13 @@ private: //disabled @see NEW */ + +/** + @todo: try to remember the meaning of this old comment: + all classes that are members parents of packed class [String] + sould be packed also to avoid sparc odd st/lduh problem + [packing is unacceptable for garbage collector] +*/ class Pooled { // the pool i'm allocated on Pool *fpool; @@ -165,16 +201,30 @@ public: //{ /// @name useful wrapper around pool void *malloc(size_t size, int place=0) const { return fpool->malloc(size, place); } + void *malloc_atomic(size_t size, int place=0) const { return fpool->malloc_atomic(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); } + void register_cleanup(void (*cleanup) (void *, void *), void *data) { fpool->register_cleanup(cleanup, data); } + void *copy(const void *buf, const size_t size) { return fpool->copy(buf, size); } + char *copy(const char *cstr) { return fpool->copy(cstr); } #ifdef XML const char *transcode_cstr(GdomeDOMString *s) { return fpool->transcode_cstr(s); } - String& transcode(GdomeDOMString *s) { return fpool->transcode(s); } + String& transcode(GdomeDOMString *s +#ifndef NO_STRING_ORIGIN + , const String *origin +#endif + ) { + return fpool->transcode(s +#ifndef NO_STRING_ORIGIN + , origin +#endif + ); + } #endif //} }; + /// useful macro for creating objects on current Pooled object Pooled::pool() #define NEW new(pool())