Class: Mmap

Inherits:
Object
  • Object
show all
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.8'
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

Instance Method Summary collapse

Constructor Details

#initializeObject

Create a new Mmap object



608
# File 'ext/mmap/mmap.c', line 608

static VALUE mm_init(argc, argv, obj) VALUE obj, *argv;

Class Method Details

.lockallObject

call-seq:

lockall(flag)

disable paging of all pages mapped. flag can be Mmap::MCL_CURRENT or Mmap::MCL_FUTURE



2165
# File 'ext/mmap/mmap.c', line 2165

static VALUE mm_mlockall(obj, flag) VALUE obj, flag;

.mlockallObject

call-seq:

lockall(flag)

disable paging of all pages mapped. flag can be Mmap::MCL_CURRENT or Mmap::MCL_FUTURE



2165
# File 'ext/mmap/mmap.c', line 2165

static VALUE mm_mlockall(obj, flag) VALUE obj, flag;

.munlockallObject

call-seq: unlockall

reenable paging



2181
# File 'ext/mmap/mmap.c', line 2181

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)



583
# File 'ext/mmap/mmap.c', line 583

static VALUE mm_s_new(argc, argv, obj) int argc;

.unlockallObject

call-seq: unlockall

reenable paging



2181
# File 'ext/mmap/mmap.c', line 2181

static VALUE mm_munlockall(obj) VALUE obj;

Instance Method Details

#<<Object

call-seq: concat(other)

append the contents of other



1552
# File 'ext/mmap/mmap.c', line 1552

static VALUE mm_concat(str1, str2) VALUE str1, str2;

#<=>(other) ⇒ Object

comparison : return -1, 0, 1



1694
# File 'ext/mmap/mmap.c', line 1694

static VALUE mm_cmp(a, b) VALUE a, b;

#==Object

call-seq: ==

comparison



1737
# File 'ext/mmap/mmap.c', line 1737

static VALUE mm_equal(a, b) VALUE a, b;

#===Object

call-seq: ==

comparison



1737
# File 'ext/mmap/mmap.c', line 1737

static VALUE mm_equal(a, b) VALUE a, b;

#=~(other) ⇒ Object

return an index of the match



1043
# File 'ext/mmap/mmap.c', line 1043

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



2061
2062
2063
# File 'ext/mmap/mmap.c', line 2061

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.



1428
# File 'ext/mmap/mmap.c', line 1428

static VALUE mm_aset_m(argc, argv, str) int argc;

#adviseObject

call-seq: madvise(advice)

advice can have the value Mmap::MADV_NORMAL, Mmap::MADV_RANDOM, Mmap::MADV_SEQUENTIAL, Mmap::MADV_WILLNEED, Mmap::MADV_DONTNEED



961
# File 'ext/mmap/mmap.c', line 961

static VALUE mm_madvise(obj, a) VALUE obj, a;

#capitalize!Object

change the first character to uppercase letter



1917
# File 'ext/mmap/mmap.c', line 1917

static VALUE mm_capitalize_bang(a) VALUE a;

#casecmp(other) ⇒ Object

only with ruby >= 1.7.1



1714
# File 'ext/mmap/mmap.c', line 1714

static VALUE mm_casecmp(a, b) VALUE a, b;

#chomp!(rs = $/) ⇒ Object

chop off the line ending character, specified by rs



1949
# File 'ext/mmap/mmap.c', line 1949

static VALUE mm_chomp_bang(argc, argv, obj) int argc;

#chop!Object

chop off the last character



1941
# File 'ext/mmap/mmap.c', line 1941

static VALUE mm_chop_bang(a) VALUE a;

#cloneObject

:nodoc:

Raises:

  • (TypeError)


14
15
16
# File 'lib/mmap.rb', line 14

def clone # :nodoc:
  raise TypeError, "can't clone instance of #{self.class}"
end

#concatObject

call-seq: concat(other)

append the contents of other



1552
# File 'ext/mmap/mmap.c', line 1552

static VALUE mm_concat(str1, str2) VALUE str1, str2;

#count(o1, *args) ⇒ Object

each parameter defines a set of character to count



2088
# File 'ext/mmap/mmap.c', line 2088

static VALUE mm_count(argc, argv, obj) int argc;

#cryptObject

crypt with salt



2012
# File 'ext/mmap/mmap.c', line 2012

static VALUE mm_crypt(a, b) VALUE a, b;

#delete!(str) ⇒ Object

delete every characters included in str



1961
# File 'ext/mmap/mmap.c', line 1961

static VALUE mm_delete_bang(argc, argv, obj) int argc;

#downcase!Object

change all uppercase character to lowercase character



1909
# File 'ext/mmap/mmap.c', line 1909

static VALUE mm_downcase_bang(a) VALUE a;

#dupObject

:nodoc:

Raises:

  • (TypeError)


18
19
20
# File 'lib/mmap.rb', line 18

def dup # :nodoc:
  raise TypeError, "can't dup instance of #{self.class}"
end

#eachObject

call-seq:

each(rs = $/, &block)

iterate on each line



2124
# File 'ext/mmap/mmap.c', line 2124

static VALUE mm_each_line(argc, argv, obj) int argc;

#each_byte(&block) ⇒ Object

iterate on each byte



2142
# File 'ext/mmap/mmap.c', line 2142

static VALUE mm_each_byte(argc, argv, obj) int argc;

#each_lineObject

call-seq:

each(rs = $/, &block)

iterate on each line



2124
# File 'ext/mmap/mmap.c', line 2124

static VALUE mm_each_line(argc, argv, obj) int argc;

#empty?Boolean

return true if the file is empty

Returns:

  • (Boolean)


1817
# File 'ext/mmap/mmap.c', line 1817

static VALUE mm_empty(a) VALUE a;

#eql?(other) ⇒ Boolean

Is this eql? to other ?

Returns:

  • (Boolean)


1762
# File 'ext/mmap/mmap.c', line 1762

static VALUE mm_eql(a, b) VALUE a, b;

#extend(count) ⇒ Object

add count bytes to the file (i.e. pre-extend the file)



449
# File 'ext/mmap/mmap.c', line 449

static VALUE mm_extend(obj, a) VALUE obj, a;

#flushObject

call-seq: msync

flush the file



878
# File 'ext/mmap/mmap.c', line 878

static VALUE mm_msync(argc, argv, obj) int argc;

#freezeObject

freeze the current file



306
# File 'ext/mmap/mmap.c', line 306

static VALUE mm_freeze(obj) VALUE obj;

#hashObject

Get the hash value



1787
# File 'ext/mmap/mmap.c', line 1787

static VALUE mm_hash(a) VALUE a;

#include?(other) ⇒ Boolean

return true if other is found

Returns:

  • (Boolean)


2020
# File 'ext/mmap/mmap.c', line 2020

static VALUE mm_include(a, b) VALUE a, b;

#indexObject

return the index of substr



2028
2029
2030
# File 'ext/mmap/mmap.c', line 2028

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



1463
# File 'ext/mmap/mmap.c', line 1463

static VALUE mm_insert(str, idx, str2) VALUE str, idx, str2;

#ipc_keyObject

Get the ipc key



260
# File 'ext/mmap/mmap.c', line 260

static VALUE mm_ipc_key(obj) VALUE obj;

#lengthObject

return the size of the file



1804
# File 'ext/mmap/mmap.c', line 1804

static VALUE mm_size(a) VALUE a;

#lockObject

call-seq: mlock

disable paging



2197
# File 'ext/mmap/mmap.c', line 2197

static VALUE mm_mlock(obj) VALUE obj;

#lstrip!Object

removes leading whitespace



1610
# File 'ext/mmap/mmap.c', line 1610

static VALUE mm_lstrip_bang(str) VALUE str;

#madviseObject

call-seq: madvise(advice)

advice can have the value Mmap::MADV_NORMAL, Mmap::MADV_RANDOM, Mmap::MADV_SEQUENTIAL, Mmap::MADV_WILLNEED, Mmap::MADV_DONTNEED



961
# File 'ext/mmap/mmap.c', line 961

static VALUE mm_madvise(obj, a) VALUE obj, a;

#match(pattern) ⇒ Object

convert pattern to a Regexp and then call match on self



1891
# File 'ext/mmap/mmap.c', line 1891

static VALUE mm_match_m(a, b) VALUE a, b;

#mlockObject

call-seq: mlock

disable paging



2197
# File 'ext/mmap/mmap.c', line 2197

static VALUE mm_mlock(obj) VALUE obj;

#mprotectObject

call-seq: mprotect(mode)

change the mode, value must be “r”, “w” or “rw”



907
# File 'ext/mmap/mmap.c', line 907

static VALUE mm_mprotect(obj, a) VALUE obj, a;

#msyncObject

call-seq: msync

flush the file



878
# File 'ext/mmap/mmap.c', line 878

static VALUE mm_msync(argc, argv, obj) int argc;

#munlockObject

call-seq: unlock

reenable paging



2223
# File 'ext/mmap/mmap.c', line 2223

static VALUE mm_munlock(obj) VALUE obj;

#munmapObject

call-seq: munmap

terminate the association



279
# File 'ext/mmap/mmap.c', line 279

static VALUE mm_unmap(obj) VALUE obj;

#protectObject

call-seq: mprotect(mode)

change the mode, value must be “r”, “w” or “rw”



907
# File 'ext/mmap/mmap.c', line 907

static VALUE mm_mprotect(obj, a) VALUE obj, a;

#reverse!Object

reverse the content of the file



1933
# File 'ext/mmap/mmap.c', line 1933

static VALUE mm_reverse_bang(a) VALUE a;

#rindex(sibstr, pos = nil) ⇒ Object

return the index of the last occurrence of substr



2037
# File 'ext/mmap/mmap.c', line 2037

static VALUE mm_rindex(argc, argv, obj) int argc;

#rstrip!Object

removes trailing whitespace



1641
# File 'ext/mmap/mmap.c', line 1641

static VALUE mm_rstrip_bang(str) VALUE str;

#scan(pattern, &block) ⇒ Object

return an array of all occurence matched by pattern



2100
# File 'ext/mmap/mmap.c', line 2100

static VALUE mm_scan(obj, a) VALUE obj, a;

#semlockObject

Create a lock



231
# File 'ext/mmap/mmap.c', line 231

static VALUE mm_semlock(argc, argv, obj) int argc;

#sizeObject

return the size of the file



1804
# File 'ext/mmap/mmap.c', line 1804

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



2061
2062
2063
# File 'ext/mmap/mmap.c', line 2061

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



1487
# File 'ext/mmap/mmap.c', line 1487

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



2079
# File 'ext/mmap/mmap.c', line 2079

static VALUE mm_split(argc, argv, obj) int argc;

#squeeze!Object

squeeze!(str)

squeezes sequences of the same characters which is included in str



1973
# File 'ext/mmap/mmap.c', line 1973

static VALUE mm_squeeze_bang(argc, argv, obj) int argc;

#strip!Object

rb_define_method(mm_cMap, “gsub!”, mm_gsub_bang, -1);



1667
# File 'ext/mmap/mmap.c', line 1667

static VALUE mm_strip_bang(str) VALUE str;

#sub!(pattern, replacement) ⇒ String? #sub!(pattern) {|match| ... } ⇒ String?

substitution

Overloads:

  • #sub!(pattern, replacement) ⇒ String?

    Returns:

    • (String, nil)
  • #sub!(pattern) {|match| ... } ⇒ String?

    Yields:

    Returns:

    • (String, nil)


1183
# File 'ext/mmap/mmap.c', line 1183

static VALUE mm_sub_bang(argc, argv, obj) int argc;

#sum(bits = 16) ⇒ Object

return a checksum



2070
# File 'ext/mmap/mmap.c', line 2070

static VALUE mm_sum(argc, argv, obj) int argc;

#swapcase!Object

replaces all lowercase characters to uppercase characters, and vice-versa



1925
# File 'ext/mmap/mmap.c', line 1925

static VALUE mm_swapcase_bang(a) VALUE a;

#syncObject

call-seq: msync

flush the file



878
# File 'ext/mmap/mmap.c', line 878

static VALUE mm_msync(argc, argv, obj) int argc;

#to_strObject

Convert object to a string



352
# File 'ext/mmap/mmap.c', line 352

static VALUE mm_to_str(obj) VALUE obj;

#tr!(search, replace) ⇒ Object

translate the character from search to replace



1985
# File 'ext/mmap/mmap.c', line 1985

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



1999
# File 'ext/mmap/mmap.c', line 1999

static VALUE mm_tr_s_bang(obj, a, b) VALUE obj, a, b;

#unlockObject

call-seq: unlock

reenable paging



2223
# File 'ext/mmap/mmap.c', line 2223

static VALUE mm_munlock(obj) VALUE obj;

#unmapObject

call-seq: munmap

terminate the association



279
# File 'ext/mmap/mmap.c', line 279

static VALUE mm_unmap(obj) VALUE obj;

#upcase!Object

replaces all lowercase characters to downcase characters



1901
# File 'ext/mmap/mmap.c', line 1901

static VALUE mm_upcase_bang(a) VALUE a;