Class: Mmap
- Inherits:
-
Object
- Object
- Mmap
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/mmap/version.rb,
lib/mmap.rb,
ext/mmap/mmap.c
Overview
Version of mmap2.
Constant Summary collapse
- VERSION =
'2.2.7'- MS_SYNC =
INT2FIX(MS_SYNC)
- MS_ASYNC =
INT2FIX(MS_ASYNC)
- MS_INVALIDATE =
INT2FIX(MS_INVALIDATE)
- PROT_READ =
INT2FIX(PROT_READ)
- PROT_WRITE =
INT2FIX(PROT_WRITE)
- PROT_EXEC =
INT2FIX(PROT_EXEC)
- PROT_NONE =
INT2FIX(PROT_NONE)
- MAP_SHARED =
INT2FIX(MAP_SHARED)
- MAP_PRIVATE =
INT2FIX(MAP_PRIVATE)
- MADV_NORMAL =
INT2FIX(MADV_NORMAL)
- MADV_RANDOM =
INT2FIX(MADV_RANDOM)
- MADV_SEQUENTIAL =
INT2FIX(MADV_SEQUENTIAL)
- MADV_WILLNEED =
INT2FIX(MADV_WILLNEED)
- MADV_DONTNEED =
INT2FIX(MADV_DONTNEED)
- MAP_DENYWRITE =
INT2FIX(MAP_DENYWRITE)
- MAP_EXECUTABLE =
INT2FIX(MAP_EXECUTABLE)
- MAP_NORESERVE =
INT2FIX(MAP_NORESERVE)
- MAP_LOCKED =
INT2FIX(MAP_LOCKED)
- MAP_GROWSDOWN =
INT2FIX(MAP_GROWSDOWN)
- MAP_ANON =
INT2FIX(MAP_ANON)
- MAP_ANONYMOUS =
INT2FIX(MAP_ANONYMOUS)
- MAP_NOSYNC =
INT2FIX(MAP_NOSYNC)
- MCL_CURRENT =
INT2FIX(MCL_CURRENT)
- MCL_FUTURE =
INT2FIX(MCL_FUTURE)
Class Method Summary collapse
-
.lockall ⇒ Object
call-seq: lockall(flag).
-
.mlockall ⇒ Object
call-seq: lockall(flag).
-
.munlockall ⇒ Object
call-seq: unlockall.
-
.new(file, mode = "r", protection = Mmap::MAP_SHARED, options = {}) ⇒ Object
create a new Mmap object.
-
.unlockall ⇒ Object
call-seq: unlockall.
Instance Method Summary collapse
-
#<< ⇒ Object
call-seq: concat(other).
-
#<=>(other) ⇒ Object
comparison : return -1, 0, 1.
-
#== ⇒ Object
call-seq: ==.
-
#=== ⇒ Object
call-seq: ==.
-
#=~(other) ⇒ Object
return an index of the match.
-
#[](*args) ⇒ Object
call-seq: [](args).
-
#[]=(args) ⇒ Object
Element assignement - with the following syntax.
-
#advise ⇒ Object
call-seq: madvise(advice).
-
#capitalize! ⇒ Object
change the first character to uppercase letter.
-
#casecmp(other) ⇒ Object
only with ruby >= 1.7.1.
-
#chomp!(rs = $/) ⇒ Object
chop off the line ending character, specified by rs.
-
#chop! ⇒ Object
chop off the last character.
-
#clone ⇒ Object
:nodoc:.
-
#concat ⇒ Object
call-seq: concat(other).
-
#count(o1, *args) ⇒ Object
each parameter defines a set of character to count.
-
#crypt ⇒ Object
crypt with salt.
-
#delete!(str) ⇒ Object
delete every characters included in str.
-
#downcase! ⇒ Object
change all uppercase character to lowercase character.
-
#dup ⇒ Object
:nodoc:.
-
#each ⇒ Object
call-seq: each(rs = $/, &block).
-
#each_byte(&block) ⇒ Object
iterate on each byte.
-
#each_line ⇒ Object
call-seq: each(rs = $/, &block).
-
#empty? ⇒ Boolean
return true if the file is empty.
-
#eql?(other) ⇒ Boolean
Is this eql? to
other?. -
#extend(count) ⇒ Object
add count bytes to the file (i.e. pre-extend the file).
-
#flush ⇒ Object
call-seq: msync.
-
#freeze ⇒ Object
freeze the current file.
-
#hash ⇒ Object
Get the hash value.
-
#include?(other) ⇒ Boolean
return true if other is found.
-
#index ⇒ Object
return the index of substr.
-
#initialize ⇒ Object
constructor
Create a new Mmap object.
-
#insert(index, str) ⇒ Object
insert str at index.
-
#ipc_key ⇒ Object
Get the ipc key.
-
#length ⇒ Object
return the size of the file.
-
#lock ⇒ Object
call-seq: mlock.
-
#lstrip! ⇒ Object
removes leading whitespace.
-
#madvise ⇒ Object
call-seq: madvise(advice).
-
#match(pattern) ⇒ Object
convert pattern to a Regexp and then call match on self.
-
#mlock ⇒ Object
call-seq: mlock.
-
#mprotect ⇒ Object
call-seq: mprotect(mode).
-
#msync ⇒ Object
call-seq: msync.
-
#munlock ⇒ Object
call-seq: unlock.
-
#munmap ⇒ Object
call-seq: munmap.
-
#protect ⇒ Object
call-seq: mprotect(mode).
-
#reverse! ⇒ Object
reverse the content of the file.
-
#rindex(sibstr, pos = nil) ⇒ Object
return the index of the last occurrence of substr.
-
#rstrip! ⇒ Object
removes trailing whitespace.
-
#scan(pattern, &block) ⇒ Object
return an array of all occurence matched by pattern.
-
#semlock ⇒ Object
Create a lock.
-
#size ⇒ Object
return the size of the file.
-
#slice(*args) ⇒ Object
call-seq: [](args).
-
#slice!(str) ⇒ Object
delete the specified portion of the file.
-
#split(sep, limit = 0) ⇒ Object
splits into a list of strings and return this array.
-
#squeeze! ⇒ Object
squeeze!(str).
-
#strip! ⇒ Object
rb_define_method(mm_cMap, “gsub!”, mm_gsub_bang, -1);.
-
#sub! ⇒ Object
substitution.
-
#sum(bits = 16) ⇒ Object
return a checksum.
-
#swapcase! ⇒ Object
replaces all lowercase characters to uppercase characters, and vice-versa.
-
#sync ⇒ Object
call-seq: msync.
-
#to_str ⇒ Object
Convert object to a string.
-
#tr!(search, replace) ⇒ Object
translate the character from search to replace.
-
#tr_s!(search, replace) ⇒ Object
translate the character from search to replace, then squeeze sequence of the same characters.
-
#unlock ⇒ Object
call-seq: unlock.
-
#unmap ⇒ Object
call-seq: munmap.
-
#upcase! ⇒ Object
replaces all lowercase characters to downcase characters.
Constructor Details
#initialize ⇒ Object
Create a new Mmap object
651 652 653 |
# File 'ext/mmap/mmap.c', line 651 static VALUE mm_init(argc, argv, obj) VALUE obj, *argv; |
Class Method Details
.lockall ⇒ Object
call-seq:
lockall(flag)
disable paging of all pages mapped. flag can be Mmap::MCL_CURRENT or Mmap::MCL_FUTURE
2379 2380 2381 |
# File 'ext/mmap/mmap.c', line 2379 static VALUE mm_mlockall(obj, flag) VALUE obj, flag; |
.mlockall ⇒ Object
call-seq:
lockall(flag)
disable paging of all pages mapped. flag can be Mmap::MCL_CURRENT or Mmap::MCL_FUTURE
2379 2380 2381 |
# File 'ext/mmap/mmap.c', line 2379 static VALUE mm_mlockall(obj, flag) VALUE obj, flag; |
.munlockall ⇒ Object
call-seq: unlockall
reenable paging
2397 2398 2399 |
# File 'ext/mmap/mmap.c', line 2397 static VALUE mm_munlockall(obj) VALUE obj; |
.new(file, mode = "r", protection = Mmap::MAP_SHARED, options = {}) ⇒ Object
create a new Mmap object
-
file
Pathname of the file, if nil is given an anonymous map is created Mmanp::MAP_ANON
-
mode
Mode to open the file, it can be “r”, “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 is Mmap::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 options length or offset is specified it will not possible to modify the size of the mapped file.
- length
-
maps length bytes from the file
- offset
-
the mapping begin at offset
- advice
-
the type of the access (see #madvise)
622 623 624 |
# File 'ext/mmap/mmap.c', line 622 static VALUE mm_s_new(argc, argv, obj) int argc; |
.unlockall ⇒ Object
call-seq: unlockall
reenable paging
2397 2398 2399 |
# File 'ext/mmap/mmap.c', line 2397 static VALUE mm_munlockall(obj) VALUE obj; |
Instance Method Details
#<< ⇒ Object
call-seq: concat(other)
append the contents of other
1649 1650 1651 |
# File 'ext/mmap/mmap.c', line 1649 static VALUE mm_concat(str1, str2) VALUE str1, str2; |
#<=>(other) ⇒ Object
comparison : return -1, 0, 1
1805 1806 1807 |
# File 'ext/mmap/mmap.c', line 1805 static VALUE mm_cmp(a, b) VALUE a, b; |
#== ⇒ Object
call-seq: ==
comparison
1852 1853 1854 |
# File 'ext/mmap/mmap.c', line 1852 static VALUE mm_equal(a, b) VALUE a, b; |
#=== ⇒ Object
call-seq: ==
comparison
1852 1853 1854 |
# File 'ext/mmap/mmap.c', line 1852 static VALUE mm_equal(a, b) VALUE a, b; |
#=~(other) ⇒ Object
return an index of the match
1108 1109 1110 |
# File 'ext/mmap/mmap.c', line 1108 static VALUE mm_match(x, y) VALUE x, y; |
#[](*args) ⇒ Object
call-seq: [](args)
Element reference - with the following syntax:
self[nth]
retrieve the nth character
self[start..last]
return a substring from start to last
self[start, length]
return a substring of lenght characters from start
2251 2252 2253 2254 2255 |
# File 'ext/mmap/mmap.c', line 2251 static VALUE mm_aref_m(int argc, VALUE *argv, VALUE obj) { return mm_bang_i(obj, MM_ORIGIN, rb_intern("[]"), argc, argv); } |
#[]=(args) ⇒ Object
Element assignement - with the following syntax
self[nth] = val
change the nth character with val
self[start..last] = val
change substring from start to last with val
self[start, len] = val
replace length characters from start with val.
1512 1513 1514 |
# File 'ext/mmap/mmap.c', line 1512 static VALUE mm_aset_m(argc, argv, str) int argc; |
#advise ⇒ Object
call-seq: madvise(advice)
advice can have the value Mmap::MADV_NORMAL, Mmap::MADV_RANDOM, Mmap::MADV_SEQUENTIAL, Mmap::MADV_WILLNEED, Mmap::MADV_DONTNEED
1020 1021 1022 |
# File 'ext/mmap/mmap.c', line 1020 static VALUE mm_madvise(obj, a) VALUE obj, a; |
#capitalize! ⇒ Object
change the first character to uppercase letter
2070 2071 2072 |
# File 'ext/mmap/mmap.c', line 2070 static VALUE mm_capitalize_bang(a) VALUE a; |
#casecmp(other) ⇒ Object
only with ruby >= 1.7.1
1827 1828 1829 |
# File 'ext/mmap/mmap.c', line 1827 static VALUE mm_casecmp(a, b) VALUE a, b; |
#chomp!(rs = $/) ⇒ Object
chop off the line ending character, specified by rs
2118 2119 2120 |
# File 'ext/mmap/mmap.c', line 2118 static VALUE mm_chomp_bang(argc, argv, obj) int argc; |
#chop! ⇒ Object
chop off the last character
2106 2107 2108 |
# File 'ext/mmap/mmap.c', line 2106 static VALUE mm_chop_bang(a) VALUE a; |
#clone ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/mmap.rb', line 14 def clone # :nodoc: raise TypeError, "can't clone instance of #{self.class}" end |
#concat ⇒ Object
call-seq: concat(other)
append the contents of other
1649 1650 1651 |
# File 'ext/mmap/mmap.c', line 1649 static VALUE mm_concat(str1, str2) VALUE str1, str2; |
#count(o1, *args) ⇒ Object
each parameter defines a set of character to count
2288 2289 2290 |
# File 'ext/mmap/mmap.c', line 2288 static VALUE mm_count(argc, argv, obj) int argc; |
#crypt ⇒ Object
crypt with salt
2188 2189 2190 |
# File 'ext/mmap/mmap.c', line 2188 static VALUE mm_crypt(a, b) VALUE a, b; |
#delete!(str) ⇒ Object
delete every characters included in str
2131 2132 2133 |
# File 'ext/mmap/mmap.c', line 2131 static VALUE mm_delete_bang(argc, argv, obj) int argc; |
#downcase! ⇒ Object
change all uppercase character to lowercase character
2058 2059 2060 |
# File 'ext/mmap/mmap.c', line 2058 static VALUE mm_downcase_bang(a) VALUE a; |
#dup ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/mmap.rb', line 18 def dup # :nodoc: raise TypeError, "can't dup instance of #{self.class}" end |
#each ⇒ Object
call-seq:
each(rs = $/, &block)
iterate on each line
2334 2335 2336 |
# File 'ext/mmap/mmap.c', line 2334 static VALUE mm_each_line(argc, argv, obj) int argc; |
#each_byte(&block) ⇒ Object
iterate on each byte
2354 2355 2356 |
# File 'ext/mmap/mmap.c', line 2354 static VALUE mm_each_byte(argc, argv, obj) int argc; |
#each_line ⇒ Object
call-seq:
each(rs = $/, &block)
iterate on each line
2334 2335 2336 |
# File 'ext/mmap/mmap.c', line 2334 static VALUE mm_each_line(argc, argv, obj) int argc; |
#empty? ⇒ Boolean
return true if the file is empty
1942 1943 1944 |
# File 'ext/mmap/mmap.c', line 1942 static VALUE mm_empty(a) VALUE a; |
#eql?(other) ⇒ Boolean
Is this eql? to other ?
1880 1881 1882 |
# File 'ext/mmap/mmap.c', line 1880 static VALUE mm_eql(a, b) VALUE a, b; |
#extend(count) ⇒ Object
add count bytes to the file (i.e. pre-extend the file)
477 478 479 |
# File 'ext/mmap/mmap.c', line 477 static VALUE mm_extend(obj, a) VALUE obj, a; |
#flush ⇒ Object
call-seq: msync
flush the file
934 935 936 |
# File 'ext/mmap/mmap.c', line 934 static VALUE mm_msync(argc, argv, obj) int argc; |
#freeze ⇒ Object
freeze the current file
319 320 321 |
# File 'ext/mmap/mmap.c', line 319 static VALUE mm_freeze(obj) VALUE obj; |
#hash ⇒ Object
Get the hash value
1908 1909 1910 |
# File 'ext/mmap/mmap.c', line 1908 static VALUE mm_hash(a) VALUE a; |
#include?(other) ⇒ Boolean
return true if other is found
2200 2201 2202 |
# File 'ext/mmap/mmap.c', line 2200 static VALUE mm_include(a, b) VALUE a, b; |
#index ⇒ Object
return the index of substr
2212 2213 2214 2215 2216 |
# File 'ext/mmap/mmap.c', line 2212 static VALUE mm_index(int argc, VALUE * argv, VALUE obj) { return mm_bang_i(obj, MM_ORIGIN, rb_intern("index"), argc, argv); } |
#insert(index, str) ⇒ Object
insert str at index
1550 1551 1552 |
# File 'ext/mmap/mmap.c', line 1550 static VALUE mm_insert(str, idx, str2) VALUE str, idx, str2; |
#ipc_key ⇒ Object
Get the ipc key
270 271 272 |
# File 'ext/mmap/mmap.c', line 270 static VALUE mm_ipc_key(obj) VALUE obj; |
#length ⇒ Object
return the size of the file
1927 1928 1929 |
# File 'ext/mmap/mmap.c', line 1927 static VALUE mm_size(a) VALUE a; |
#lock ⇒ Object
call-seq: mlock
disable paging
2415 2416 2417 |
# File 'ext/mmap/mmap.c', line 2415 static VALUE mm_mlock(obj) VALUE obj; |
#lstrip! ⇒ Object
removes leading whitespace
1713 1714 1715 |
# File 'ext/mmap/mmap.c', line 1713 static VALUE mm_lstrip_bang(str) VALUE str; |
#madvise ⇒ Object
call-seq: madvise(advice)
advice can have the value Mmap::MADV_NORMAL, Mmap::MADV_RANDOM, Mmap::MADV_SEQUENTIAL, Mmap::MADV_WILLNEED, Mmap::MADV_DONTNEED
1020 1021 1022 |
# File 'ext/mmap/mmap.c', line 1020 static VALUE mm_madvise(obj, a) VALUE obj, a; |
#match(pattern) ⇒ Object
convert pattern to a Regexp and then call match on self
2032 2033 2034 |
# File 'ext/mmap/mmap.c', line 2032 static VALUE mm_match_m(a, b) VALUE a, b; |
#mlock ⇒ Object
call-seq: mlock
disable paging
2415 2416 2417 |
# File 'ext/mmap/mmap.c', line 2415 static VALUE mm_mlock(obj) VALUE obj; |
#mprotect ⇒ Object
call-seq: mprotect(mode)
change the mode, value must be “r”, “w” or “rw”
965 966 967 |
# File 'ext/mmap/mmap.c', line 965 static VALUE mm_mprotect(obj, a) VALUE obj, a; |
#msync ⇒ Object
call-seq: msync
flush the file
934 935 936 |
# File 'ext/mmap/mmap.c', line 934 static VALUE mm_msync(argc, argv, obj) int argc; |
#munlock ⇒ Object
call-seq: unlock
reenable paging
2443 2444 2445 |
# File 'ext/mmap/mmap.c', line 2443 static VALUE mm_munlock(obj) VALUE obj; |
#munmap ⇒ Object
call-seq: munmap
terminate the association
291 292 293 |
# File 'ext/mmap/mmap.c', line 291 static VALUE mm_unmap(obj) VALUE obj; |
#protect ⇒ Object
call-seq: mprotect(mode)
change the mode, value must be “r”, “w” or “rw”
965 966 967 |
# File 'ext/mmap/mmap.c', line 965 static VALUE mm_mprotect(obj, a) VALUE obj, a; |
#reverse! ⇒ Object
reverse the content of the file
2094 2095 2096 |
# File 'ext/mmap/mmap.c', line 2094 static VALUE mm_reverse_bang(a) VALUE a; |
#rindex(sibstr, pos = nil) ⇒ Object
return the index of the last occurrence of substr
2223 2224 2225 |
# File 'ext/mmap/mmap.c', line 2223 static VALUE mm_rindex(argc, argv, obj) int argc; |
#rstrip! ⇒ Object
removes trailing whitespace
1746 1747 1748 |
# File 'ext/mmap/mmap.c', line 1746 static VALUE mm_rstrip_bang(str) VALUE str; |
#scan(pattern, &block) ⇒ Object
return an array of all occurence matched by pattern
2308 2309 2310 |
# File 'ext/mmap/mmap.c', line 2308 static VALUE mm_scan(obj, a) VALUE obj, a; |
#semlock ⇒ Object
Create a lock
238 239 240 |
# File 'ext/mmap/mmap.c', line 238 static VALUE mm_semlock(argc, argv, obj) int argc; |
#size ⇒ Object
return the size of the file
1927 1928 1929 |
# File 'ext/mmap/mmap.c', line 1927 static VALUE mm_size(a) VALUE a; |
#slice(*args) ⇒ Object
call-seq: [](args)
Element reference - with the following syntax:
self[nth]
retrieve the nth character
self[start..last]
return a substring from start to last
self[start, length]
return a substring of lenght characters from start
2251 2252 2253 2254 2255 |
# File 'ext/mmap/mmap.c', line 2251 static VALUE mm_aref_m(int argc, VALUE *argv, VALUE obj) { return mm_bang_i(obj, MM_ORIGIN, rb_intern("[]"), argc, argv); } |
#slice!(str) ⇒ Object
delete the specified portion of the file
1577 1578 1579 |
# File 'ext/mmap/mmap.c', line 1577 static VALUE mm_slice_bang(argc, argv, str) int argc; |
#split(sep, limit = 0) ⇒ Object
splits into a list of strings and return this array
2275 2276 2277 |
# File 'ext/mmap/mmap.c', line 2275 static VALUE mm_split(argc, argv, obj) int argc; |
#squeeze! ⇒ Object
squeeze!(str)
squeezes sequences of the same characters which is included in str
2144 2145 2146 |
# File 'ext/mmap/mmap.c', line 2144 static VALUE mm_squeeze_bang(argc, argv, obj) int argc; |
#strip! ⇒ Object
rb_define_method(mm_cMap, “gsub!”, mm_gsub_bang, -1);
1774 1775 1776 |
# File 'ext/mmap/mmap.c', line 1774 static VALUE mm_strip_bang(str) VALUE str; |
#sub!(pattern, replacement) ⇒ String? #sub!(pattern) {|match| ... } ⇒ String?
substitution
1253 1254 1255 |
# File 'ext/mmap/mmap.c', line 1253 static VALUE mm_sub_bang(argc, argv, obj) int argc; |
#sum(bits = 16) ⇒ Object
return a checksum
2262 2263 2264 |
# File 'ext/mmap/mmap.c', line 2262 static VALUE mm_sum(argc, argv, obj) int argc; |
#swapcase! ⇒ Object
replaces all lowercase characters to uppercase characters, and vice-versa
2082 2083 2084 |
# File 'ext/mmap/mmap.c', line 2082 static VALUE mm_swapcase_bang(a) VALUE a; |
#sync ⇒ Object
call-seq: msync
flush the file
934 935 936 |
# File 'ext/mmap/mmap.c', line 934 static VALUE mm_msync(argc, argv, obj) int argc; |
#to_str ⇒ Object
Convert object to a string
369 370 371 |
# File 'ext/mmap/mmap.c', line 369 static VALUE mm_to_str(obj) VALUE obj; |
#tr!(search, replace) ⇒ Object
translate the character from search to replace
2157 2158 2159 |
# File 'ext/mmap/mmap.c', line 2157 static VALUE mm_tr_bang(obj, a, b) VALUE obj, a, b; |
#tr_s!(search, replace) ⇒ Object
translate the character from search to replace, then squeeze sequence of the same characters
2173 2174 2175 |
# File 'ext/mmap/mmap.c', line 2173 static VALUE mm_tr_s_bang(obj, a, b) VALUE obj, a, b; |
#unlock ⇒ Object
call-seq: unlock
reenable paging
2443 2444 2445 |
# File 'ext/mmap/mmap.c', line 2443 static VALUE mm_munlock(obj) VALUE obj; |
#unmap ⇒ Object
call-seq: munmap
terminate the association
291 292 293 |
# File 'ext/mmap/mmap.c', line 291 static VALUE mm_unmap(obj) VALUE obj; |
#upcase! ⇒ Object
replaces all lowercase characters to downcase characters
2046 2047 2048 |
# File 'ext/mmap/mmap.c', line 2046 static VALUE mm_upcase_bang(a) VALUE a; |