map_anonymous#
Allocate a fresh memory region backed by no file and attach it to a scalar.
תקציר#
map_anonymous my $buf, 4096; # shared (default)
map_anonymous my $buf, 4096, 'shared'; # visible to forked children
map_anonymous my $buf, 1 << 20, 'private'; # process-local
ארגומנטים#
$lvalue- scalar to receive the mapping.$length- size of the region in bytes. Must be greater than zero.$type-'shared'or'private'. A shared region is inherited by child processes created withfork; a private region is not. Defaults to'shared'.
דוגמאות#
Share a buffer with a forked child:
map_anonymous my $counter, 16, 'shared';
substr $counter, 0, 16, pack('Q', 0) . pack('Q', 0);
if (fork() == 0) {
substr $counter, 0, 8, pack('Q', 42);
exit;
}
Allocate a private scratch region:
map_anonymous my $scratch, 1_000_000, 'private';
substr $scratch, 0, 5, "hello";
מקרי קצה#
Zero-length anonymous maps are rejected.
Any
$typeother than'shared'or'private'raises an exception.
הבדלים מן ה-upstream#
Fully compatible with upstream File::Map 0.71.
ראו גם#
map_file- map a file instead of raw memory.sys_map- take rawmmap(2)flags.remap- grow or shrink a private anonymous mapping on Linux.