--- parser3/src/include/pa_pool.h 2002/08/01 11:41:15 1.83 +++ parser3/src/include/pa_pool.h 2003/03/18 09:53:01 1.86.4.2 @@ -1,7 +1,7 @@ /** @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: Alexandr Petrosian (http://paf.design.ru) */ @@ -9,7 +9,7 @@ #ifndef PA_POOL_H #define PA_POOL_H -static const char* IDENT_POOL_H="$Date: 2002/08/01 11:41:15 $"; +static const char* IDENT_POOL_H="$Date: 2003/03/18 09:53:01 $"; #include "pa_config_includes.h" @@ -37,6 +37,12 @@ class Pool { public: Pool(void *astorage); + ~Pool(); + + //{@ collector issues + void collect_garbage(); + void log_high_watermark(const char *msg); + //}@ //{@ statistics size_t total_allocated() { return ftotal_allocated; } @@ -47,6 +53,11 @@ public: 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,11 +67,16 @@ 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(); } + //{@ 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(); @@ -76,11 +92,19 @@ public: /// @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) @@ -99,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: @@ -144,9 +171,12 @@ private: //disabled @see NEW */ -// all classes that are members parents of packed class [String] -// sould be packed also to avoid sparc odd st/lduh problem -#include "pa_pragma_pack_begin.h" +/** + @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; @@ -171,17 +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 //} }; -#include "pa_pragma_pack_end.h" + /// useful macro for creating objects on current Pooled object Pooled::pool() #define NEW new(pool())