Cavil-Matcher
view release on metacpan or search on metacpan
src/matcher.h view on Meta::CPAN
#include <string>
#include <vector>
// One resolved match returned to the caller.
struct ResolvedMatch {
uint32_t pattern;
int sline;
int eline;
};
// RAII read-only mmap of a file. munmaps on destruction; keeps a Segment's backing memory alive.
class MappedFile {
public:
MappedFile() = default;
~MappedFile();
bool map(const std::string& path);
const char* data() const { return _data; }
size_t size() const { return _size; }
private:
const char* _data = nullptr;
t/13shared.t view on Meta::CPAN
my $scan_file = (glob('t/fixtures/licenses/04license.*.txt'))[0];
my $before = rss_anon_bytes();
my $N = 25;
my @keep;
for (1 .. $N) {
my $m = Cavil::Matcher::init_matcher();
ok($m->attach($seg), 'attached shared segment') if $_ == 1;
$m->attach($seg) unless $_ == 1;
$m->find_matches($scan_file); # fault pages in
push @keep, $m; # keep all matchers alive simultaneously
}
my $delta = rss_anon_bytes() - $before;
# A per-matcher heap copy would cost about N x F of anonymous memory. The mmap-shared design costs
# essentially none. Assert the private-memory growth is far below even a single copy of the segment.
diag(sprintf(
'attached %d matchers over a %d-byte segment; RssAnon grew %d bytes (heap-copy would be ~%d)',
$N, $F, $delta, $N * $F
));
cmp_ok($delta, '<', $F, 'attaching N matchers adds less private memory than a single segment copy');
( run in 1.931 second using v1.01-cache-2.11-cpan-14f38c9f855 )