The Mmap class implement memory-mapped file objects
require 'mmap'
mmap = Mmap.new(__FILE__)
mmap.advise(Mmap::MADV_SEQUENTIAL)
mmap.each do |line|
puts line
endgem install mmap
rake docs
WARNING: The variables
Object
ComparableEnumerable
-
lockall(flag):
disable paging of all pages mapped.|flag|can beMmap::MCL_CURRENTorMmap::MCL_FUTURE -
new(file, mode = "r", protection = Mmap::MAP_SHARED, options = {})
new(nil, length, protection = Mmap::MAP_SHARED, options = {}):
create a new Mmap object-
file: Pathname of the file, ifnilis given an anonymous map is createdMmanp::MAP_ANON -
mode: Mode to open the file, it can ber,w,rw,a -
protection: specify the nature of the mapping-
Mmap::MAP_SHARED: Creates a mapping that's shared with all other processes mapping the same areas of the file. The default value isMmap::MAP_SHARED -
Mmap::MAP_PRIVATE: Creates a private copy-on-write mapping, so changes to the contents of the mmap object will be private to this process
-
-
options: Hash. If one of the optionslengthoroffsetis specified it will not possible to modify the size of the mapped file.length: Mapslengthbytes from the fileoffset: The mapping begin atoffsetadvice: The type of the access (see#madvise)
-
-
unlockall: reenable paging
-
extend(count): addcountbytes to the file (i.e. pre-extend the file) -
madvise(advice):advicecan have the valueMmap::MADV_NORMAL,Mmap::MADV_RANDOM,Mmap::MADV_SEQUENTIAL,Mmap::MADV_WILLNEED,Mmap::MADV_DONTNEED -
mprotect(mode): change the mode, value must ber,worrw -
mlock: disable paging -
msync
flush: flush the file -
munlock: reenable paging -
munmap: terminate the association
-
self == other: comparison -
self > other: comparison -
self >= other: comparison -
self < other: comparison -
self <= other: comparison -
self === other: used forcasecomparison -
self << other: appendothertoself -
self =~ other: return an index of the match -
self[nth]: retrieve thenthcharacter -
self[start..last]: return a substring fromstarttolast -
self[start, length]: return a substring oflenghtcharacters fromstart -
self[nth] = val: change thenthcharacter withval -
self[start..last] = val: change substring fromstarttolastwithval -
self[start, len] = val: replacelengthcharacters fromstartwithval. -
self <=> other: comparison : return -1, 0, 1 -
casecmp(other) >= 1.7.1: -
concat(other): append the contents ofother -
capitalize!: change the first character to uppercase letter -
chop!: chop off the last character -
chomp!([rs]): chop off the line ending character, specified byrs -
count(o1 [, o2, ...]): each parameter defines a set of character to count -
crypt(salt): crypt withsalt -
delete!(str): delete every characters included instr -
downcase!: change all uppercase character to lowercase character -
each_byte {|char|...}: iterate on each byte -
each([rs]) {|line|...}: -each_line([rs]) {|line|...}: iterate on each line -
empty?: returntrueif the file is empty -
freeze: freeze the current file -
frozen: returntrueif the file is frozen -
gsub!(pattern, replace): global substitution -
gsub!(pattern) {|str|...}: global substitution -
include?(other): returntrueifotheris found -
index(substr[, pos]): return the index ofsubstr -
insert(index, str) >= 1.7.1: insertstratindex -
length: return the size of the file -
reverse!: reverse the content of the file -
rindex(substr[, pos]): return the index of the last occurrence ofsubstr -
scan(pattern): return an array of all occurence matched bypattern -
scan(pattern) {|str| ...}: iterate through the file, matching thepattern -
size: return the size of the file -
slice: same than[] -
slice!: delete the specified portion of the file -
split([sep[, limit]]): splits into a list of strings and return this array -
squeeze!([str]): squeezes sequences of the same characters which is included instr -
strip!: removes leading and trailing whitespace -
sub!(pattern, replace): substitution -
sub!(pattern) {|str| ...}: substitution -
sum([bits]): return a checksum -
swapcase!: replaces all lowercase characters to uppercase characters, and vice-versa -
tr!(search, replace): translate the character fromsearchtoreplace -
tr_s!(search, replace): translate the character fromsearchtoreplace, then squeeze sequence of the same characters -
upcase!: replaces all lowercase characters to downcase characters
This extension module is copyrighted free software by Guy Decoux
You can redistribute it and/or modify it under the same term as Ruby.
Guy Decoux ts@moulon.inra.fr