Re: [ssax-sxml] ssax thread-safe? example
Brought to you by:
oleg
From: Bruce B. <ba...@en...> - 2003-12-16 16:54:23
|
That was it. Thanks so much for pointing this out -- the words 'static buffer' kind of stand out, don't they? Works like a champ now. Joerg F. Wittenberger wrote: > Hello Bruce, > > Disclaimer: I'm _not_ activily using the SSAX parser. So please > forvige me, if I'm citeing old code here. > > Bruce Butterfield <ba...@en...> writes: > > >> filename="threadtest.ss" >> >>(require (lib "thread.ss") >> (lib "date.ss") >> (lib "ssax.ss" "ssax") >> (lib "myenv.ss" "ssax") >> (lib "input-parse.ss" "ssax") > > >>From input-parse.scm > > ; Procedure input-parse:init-buffer > ; returns an initial buffer for next-token* procedures. > ; The input-parse:init-buffer may allocate a new buffer per each invocation: > ; (define (input-parse:init-buffer) (make-string 32)) > ; Size 32 turns out to be fairly good, on average. > ; That policy is good only when a Scheme system is multi-threaded with > ; preemptive scheduling, or when a Scheme system supports shared substrings. > ; In all the other cases, it's better for input-parse:init-buffer to > ; return the same static buffer. next-token* functions return a copy > ; (a substring) of accumulated data, so the same buffer can be reused. > ; We shouldn't worry about new token being too large: next-token will use > ; a larger buffer automatically. Still, the best size for the static buffer > ; is to allow most of the tokens to fit in. > ; Using a static buffer _dramatically_ reduces the amount of produced garbage > ; (e.g., during XML parsing). > (define input-parse:init-buffer > (let ((buffer (make-string 512))) > (lambda () buffer))) > > ... > > So you might want to make sure that there is something alon the lines > of: > > (define input-parse:init-buffer > (lambda () (make-string 512))) > > in your code. > > best regards > > /J?rg > |