Re: Excessive dynamic allocation when using boost::split(..., > boost::is_any_of(", "))

Phil Endecott via Boost-users <[email protected]>
Newsgroups gmane.comp.lib.boost.user
Message-ID <[email protected]>
Hi Dominique,

Dominique Pelle wrote:
> This following program shows many allocations coming
> from boost::split(..., boost::is_any_of(",")):
> When using boost::is_any_of(","), there are 7 dynamic allocations
> per loop iteration whereas when using the lambda predicate,
> there are 0 dynamic allocation per loop as shown below:

See this thread from 2008:

   https://lists.boost.org/Archives/boost//2008/02/133396.php

There are some benchmarks in my reply here:

   https://lists.boost.org/Archives/boost//2008/02/133415.php

I observed that C's strcspn was one of the better choices,
but it could be beaten for search sets known at compile time
with this:

template <char c0> bool is_any_of(char c) {
    return (c==c0);
}

template <char c0, char c1> bool is_any_of(char c) {
    return (c==c0) || is_any_of<c1>(c);
}

template <char c0, char c1, char c2> bool is_any_of(char c) {
    return (c==c0) || is_any_of<c1,c2>(c);
}

etc.

(Yes, I was writing that before variadic templates!)

I don't know if boost::is_any_of has changed in the 14 years
since then, but your observation suggests not.


Regards, Phil.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.