A parser pool that enables caching of grammars. The caching parser
pool is constructed with a specific symbol table and grammar pool
that has already been populated with the grammars used by the
application.
Once the caching parser pool is constructed, specific parser
instances are created by calling the appropriate factory method
on the parser pool.
Note: There is a performance penalty for using
a caching parser pool due to thread safety. Access to the symbol
table and grammar pool must be synchronized to ensure the safe
operation of the symbol table and grammar pool.
Note: If performance is critical, then another
mechanism needs to be used instead of the caching parser pool.
One approach would be to create parser instances that do not
share these structures. Instead, each instance would get its
own copy to use while parsing. This avoids the synchronization
overhead at the expense of more memory and the time required
to copy the structures for each new parser instance. And even
when a parser instance is re-used, there is a potential for a
memory leak due to new symbols being added to the symbol table
over time. In other words, always take caution to make sure
that your application is thread-safe and avoids leaking memory. |