New regex: Find?
dsimcha
dsimcha at yahoo.com
Mon May 4 18:18:08 PDT 2009
== Quote from Joel C. Salomon (joelcsalomon at gmail.com)'s article
> dsimcha wrote:
> > Is there an *efficient* way to simply test whether a given string contains a
> > given regex in the new std.regex? Using match() and testing for empty works,
> > but this apparently triggers a bunch of unnecessary heap allocation. If not,
> > is this a universal enough feature to warrant an enhancement request?
> You mean to search for a regex match without constructing the regex
> engine? Good luck with that.
> —Joel Salomon
Actually, the behavior Andrei describes is what I wanted: One allocation to
construct the regex engine, amortized. However, contrary to what Andrei said,
match() apparently allocates additional memory on each call. The following
program leaks memory like a sieve when the GC is disabled:
import std.regex, core.memory;
void main() {
string s = "This is only a test. Repeat, this is only a test.";
auto r = regex("is.only");
GC.disable;
while(true) {
auto m = match(s, r);
}
}
More information about the Digitalmars-d
mailing list