Re: [pcre-dev] Proposal for a new API for PCRE

Top Page
Delete this message
Author: Graycode
Date:  
To: pcre-dev
Subject: Re: [pcre-dev] Proposal for a new API for PCRE
I'd like to be able to define the storage for match_data to be on a
thread's stack, mainly to avoid memory allocation / free for every
execution. Its content can still be opaque, the values can be
initialized / assigned by PCRE2. Because that storage is user-defined,
its size should be passed into PCRE2 to enable detection of an error
when compiling with one version but later linking with another PCRE2
version that defines a larger structure.

For the example of 8.1 option A, I'm thinking of something like:

size_t ovector[20];
pcre2_match_data mymatch;
pcre2_match_data * match_data =
pcre2_init_match_data(context, &mymatch, sizeof(mymatch), ovector, 20);


Consider having a flag within pcre2_match_data to indicate how its
storage was obtained. Then later if a call is made to
pcre2_free_match_data(match_data) don't release the memory unless it
was truly allocated by having used pcre2_create_match_data().

Thanks for the terrific work.


Graycode