1. There is no APR equivalent for free, as it is neither needed nor desired.   Simply allocate your memory from a pool, and destroy the pool when it is no longer needed.  I would suggest making a subpool on RE create and bury it in an opaque pointer describing your RE, if you're actually going to go whole-hog on this. Me?   I use the OS regexec/regcomp  (search only) and register an apr_pool_cleanup handler to avoid leaking memory.

2. Personally, I would never roll my own search and replace except under exceptional circumstances. That said, your approach doesn't sound unreasonable, but it's difficult to say what your problem is without profiling the code and looking at memory consumption. Start by consulting the literature, S&R is a well-understood problem; and maybe google some stuff on ropes, they may serve you better than strings.

Here's a paper on ropes which discusses concatenation, which *should* be where you're spending your search and replace time: www.cs.ubc.ca/local/reading/proceedings/spe91-95/spe/vol25/issue12/spe986.pdf

Note - if your S&R is regexp instead of strcmp, you could also be spending most of your time in the regex state machine. Profile!

Wes

On Mon, Dec 29, 2008 at 2:43 PM, Jacques Amar <jalist@amar.com> wrote:
Hello,

Sorry if this is already answered elsewhere, couldn't locate it.

  1. Is there already a Perl Compatible Regular Expression (PCRE) wrapper for APR? My understanding is that we simply need to take over the calls to malloc and free with the provided function pointers. malloc seems easy enough to map to a pool. I'm having a conceptual problem with the free portion.
  2. I also rolled my own search and replace routines - but the performance sucks on large input. Any suggestions on how to manipulate strings with the cutting and stitching required? I've used an APR_ARRAY push during processing and cat it all together once done. perl code doing the same s/// takes way less time.
Let me know if I need to provide code examples.
Thanks

Jacques