mmap-ruby 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +109 -0
- data/Rakefile +16 -0
- data/ext/mmap_ruby/mmap_ruby.c +1 -1
- data/lib/mmap-ruby/version.rb +1 -1
- metadata +3 -7
- data/lib/mmap-ruby/mmap_ruby.bundle +0 -0
- data/mmap-ruby.gemspec +0 -23
- data/tmp/arm64-darwin25/stage/CHANGELOG.md +0 -5
- data/tmp/arm64-darwin25/stage/README.md +0 -92
- data/tmp/arm64-darwin25/stage/mmap-ruby.gemspec +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cff047cba008954ea5ddce08477b84aff540d02ffcfe7b789d5f82438922b39
|
|
4
|
+
data.tar.gz: 1951e7040dce367873d893ef8a828482bdcfa5336a008250b19ebda67117f5bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9d22bd917cc5db3d365d37231a43c4de2057417bbe86c6dde208089c2c30a6f0246c4cdf0f07a59d83698d36281b7b8b7d5b1e2688b5989ffd2e27bcdf68755
|
|
7
|
+
data.tar.gz: 9017018659a935304f64cd2e3ea46c9fe7f77c97b94bccac57c1da823aca049d6b036a6b0f9e9a39b08f35a858eabe4f149b746dae7ef7b3e16ef721f17a1a83
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -53,6 +53,115 @@ p mmap.size == 5 + 2 * PAGESIZE
|
|
|
53
53
|
File.delete("aa")
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
```
|
|
57
|
+
> bundle exec ruby examples/example.rb
|
|
58
|
+
true
|
|
59
|
+
true
|
|
60
|
+
true
|
|
61
|
+
true
|
|
62
|
+
true
|
|
63
|
+
true
|
|
64
|
+
OK: can't change the size of a fixed map
|
|
65
|
+
true
|
|
66
|
+
true
|
|
67
|
+
true
|
|
68
|
+
true
|
|
69
|
+
true
|
|
70
|
+
true
|
|
71
|
+
true
|
|
72
|
+
true
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Benchmark (Producer-Consumer IPC with validation):**
|
|
76
|
+
|
|
77
|
+
Tests scenario where one process writes 1M small messages sequentially
|
|
78
|
+
while another process reads and validates each message as it arrives.
|
|
79
|
+
Simulates real-time data processing where consumer must validate each
|
|
80
|
+
item individually without bulk operations or synchronization.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
# frozen_string_literal: true
|
|
84
|
+
|
|
85
|
+
require "mmap-ruby"
|
|
86
|
+
|
|
87
|
+
puts RUBY_DESCRIPTION
|
|
88
|
+
puts "mmap-ruby version #{MmapRuby::VERSION}"
|
|
89
|
+
|
|
90
|
+
t1 = Time.now
|
|
91
|
+
|
|
92
|
+
reader, writer = IO.pipe
|
|
93
|
+
|
|
94
|
+
fork do
|
|
95
|
+
reader.close
|
|
96
|
+
1_000_000.times do
|
|
97
|
+
writer.write("aa\n")
|
|
98
|
+
end
|
|
99
|
+
writer.write("zz\n")
|
|
100
|
+
writer.close
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
writer.close
|
|
104
|
+
|
|
105
|
+
line = ""
|
|
106
|
+
loop do
|
|
107
|
+
begin
|
|
108
|
+
line = reader.read_nonblock(3)
|
|
109
|
+
break if line == "zz\n"
|
|
110
|
+
raise "Expected 'aa\n', got '#{line}'" unless line == "aa\n"
|
|
111
|
+
rescue IO::WaitReadable
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
reader.close
|
|
116
|
+
|
|
117
|
+
t2 = Time.now
|
|
118
|
+
puts "Time taken for IO.pipe: #{t2 - t1} seconds"
|
|
119
|
+
|
|
120
|
+
file = File.open("example.txt", "w+")
|
|
121
|
+
file.write("\0" * 3_000_003)
|
|
122
|
+
file.close
|
|
123
|
+
|
|
124
|
+
t3 = Time.now
|
|
125
|
+
|
|
126
|
+
mmap = Mmap.new(file.path, "rw")
|
|
127
|
+
|
|
128
|
+
fork do
|
|
129
|
+
1_000_000.times do |i|
|
|
130
|
+
mmap[i * 3, 3] = "aa\n"
|
|
131
|
+
end
|
|
132
|
+
mmap[3_000_000, 3] = "zz\n"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
line = ""
|
|
136
|
+
index = 0
|
|
137
|
+
loop do
|
|
138
|
+
line = mmap[index, 3]
|
|
139
|
+
index += 3
|
|
140
|
+
|
|
141
|
+
if line == "\0\0\0"
|
|
142
|
+
next
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
break if line == "zz\n"
|
|
146
|
+
raise "Expected 'aa\n', got '#{line}'" unless line == "aa\n"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
mmap.unmap
|
|
150
|
+
|
|
151
|
+
t4 = Time.now
|
|
152
|
+
puts "Time taken for Mmap: #{t4 - t3} seconds"
|
|
153
|
+
|
|
154
|
+
File.delete("example.txt")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
> bundle exec ruby examples/benchmark.rb
|
|
159
|
+
ruby 4.0.0dev (2025-11-10T10:12:35Z master 557eec792e) +YJIT +PRISM [arm64-darwin25]
|
|
160
|
+
mmap-ruby version 0.1.0
|
|
161
|
+
Time taken for IO.pipe: 1.215664 seconds
|
|
162
|
+
Time taken for Mmap: 0.139914 seconds
|
|
163
|
+
```
|
|
164
|
+
|
|
56
165
|
## Installation
|
|
57
166
|
|
|
58
167
|
Install the gem and add to the application's Gemfile by executing:
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "minitest/test_task"
|
|
5
|
+
require "rake/extensiontask"
|
|
6
|
+
|
|
7
|
+
GEMSPEC = Gem::Specification.load("mmap-ruby.gemspec")
|
|
8
|
+
|
|
9
|
+
Minitest::TestTask.create
|
|
10
|
+
|
|
11
|
+
Rake::ExtensionTask.new("mmap_ruby", GEMSPEC) do |ext|
|
|
12
|
+
ext.lib_dir = "lib/mmap-ruby"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
task build: :compile
|
|
16
|
+
task default: %i[clobber compile test]
|
data/ext/mmap_ruby/mmap_ruby.c
CHANGED
|
@@ -73,9 +73,9 @@ typedef struct {
|
|
|
73
73
|
|
|
74
74
|
void *(*mmap_func)(void *, size_t, int, int, int, off_t) = mmap;
|
|
75
75
|
|
|
76
|
+
static VALUE rb_cMmap_index(int argc, VALUE *argv, VALUE self);
|
|
76
77
|
static void mmap_update(mmap_t *str, long beg, long len, VALUE val);
|
|
77
78
|
static void mmap_subpat_set(VALUE obj, VALUE re, int offset, VALUE val);
|
|
78
|
-
static VALUE rb_cMmap_index(int argc, VALUE *argv, VALUE self);
|
|
79
79
|
static void mmap_realloc(mmap_t *mmap, size_t len);
|
|
80
80
|
static void mmap_expandf(mmap_t *mmap, size_t len);
|
|
81
81
|
|
data/lib/mmap-ruby/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mmap-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guy Decoux
|
|
@@ -22,18 +22,14 @@ extra_rdoc_files: []
|
|
|
22
22
|
files:
|
|
23
23
|
- CHANGELOG.md
|
|
24
24
|
- README.md
|
|
25
|
+
- Rakefile
|
|
25
26
|
- ext/mmap_ruby/extconf.rb
|
|
26
27
|
- ext/mmap_ruby/mmap
|
|
27
28
|
- ext/mmap_ruby/mmap_ruby.c
|
|
28
29
|
- ext/mmap_ruby/mmap_ruby.h
|
|
29
30
|
- lib/mmap-ruby.rb
|
|
30
31
|
- lib/mmap-ruby/mmap.rb
|
|
31
|
-
- lib/mmap-ruby/mmap_ruby.bundle
|
|
32
32
|
- lib/mmap-ruby/version.rb
|
|
33
|
-
- mmap-ruby.gemspec
|
|
34
|
-
- tmp/arm64-darwin25/stage/CHANGELOG.md
|
|
35
|
-
- tmp/arm64-darwin25/stage/README.md
|
|
36
|
-
- tmp/arm64-darwin25/stage/mmap-ruby.gemspec
|
|
37
33
|
homepage: https://github.com/joshuay03/mmap-ruby
|
|
38
34
|
licenses:
|
|
39
35
|
- https://www.ruby-lang.org/en/about/license.txt
|
|
@@ -55,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
55
51
|
- !ruby/object:Gem::Version
|
|
56
52
|
version: '0'
|
|
57
53
|
requirements: []
|
|
58
|
-
rubygems_version:
|
|
54
|
+
rubygems_version: 4.0.0.dev
|
|
59
55
|
specification_version: 4
|
|
60
56
|
summary: mmap wrapper for Ruby
|
|
61
57
|
test_files: []
|
|
Binary file
|
data/mmap-ruby.gemspec
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/mmap-ruby/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "mmap-ruby"
|
|
7
|
-
spec.version = MmapRuby::VERSION
|
|
8
|
-
spec.authors = ["Guy Decoux", "Aaron Patterson", "Joshua Young"]
|
|
9
|
-
spec.email = ["ts@moulon.inra.fr", "tenderlove@github.com", "djry1999@gmail.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "mmap wrapper for Ruby"
|
|
12
|
-
spec.homepage = "https://github.com/joshuay03/mmap-ruby"
|
|
13
|
-
spec.license = "https://www.ruby-lang.org/en/about/license.txt"
|
|
14
|
-
spec.required_ruby_version = ">= 3.3.0"
|
|
15
|
-
|
|
16
|
-
spec.metadata["documentation_uri"] = "https://joshuay03.github.io/mmap-ruby/"
|
|
17
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
|
18
|
-
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
19
|
-
|
|
20
|
-
spec.files = Dir["lib/**/*", "ext/**/*", "**/*.{gemspec,md,txt}"]
|
|
21
|
-
spec.require_paths = ["lib"]
|
|
22
|
-
spec.extensions = ["ext/mmap_ruby/extconf.rb"]
|
|
23
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# MmapRuby
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
[`mmap`](https://en.wikipedia.org/wiki/Mmap) wrapper for Ruby.
|
|
7
|
-
|
|
8
|
-
A modern fork of https://github.com/tenderlove/mmap.
|
|
9
|
-
|
|
10
|
-
**Docs:** https://joshuay03.github.io/mmap-ruby
|
|
11
|
-
|
|
12
|
-
**Example:**
|
|
13
|
-
|
|
14
|
-
```ruby
|
|
15
|
-
# frozen_string_literal: true
|
|
16
|
-
|
|
17
|
-
require "mmap-ruby"
|
|
18
|
-
|
|
19
|
-
PAGESIZE = 4096
|
|
20
|
-
|
|
21
|
-
file = File.open("aa", "w")
|
|
22
|
-
file.write("\0" * PAGESIZE)
|
|
23
|
-
file.write("test")
|
|
24
|
-
file.write("\0" * PAGESIZE)
|
|
25
|
-
file.close
|
|
26
|
-
|
|
27
|
-
mmap = Mmap.new("aa", "rw", offset: 0)
|
|
28
|
-
p mmap.size == "test".size + (2 * PAGESIZE)
|
|
29
|
-
p mmap.scan(/[a-z.]+/) == ["test"]
|
|
30
|
-
p mmap.index("test") == PAGESIZE
|
|
31
|
-
p mmap.rindex("test") == PAGESIZE
|
|
32
|
-
p mmap.sub!(/[a-z.]+/, "toto") == mmap
|
|
33
|
-
p mmap.scan(/[a-z.]+/) == ["toto"]
|
|
34
|
-
begin
|
|
35
|
-
mmap.sub!(/[a-z.]+/, "alpha")
|
|
36
|
-
puts "not OK, must give an error"
|
|
37
|
-
rescue
|
|
38
|
-
puts "OK: #$!"
|
|
39
|
-
end
|
|
40
|
-
mmap.munmap
|
|
41
|
-
|
|
42
|
-
mmap = Mmap.new("aa", "rw")
|
|
43
|
-
p mmap.index("toto") == PAGESIZE
|
|
44
|
-
p mmap.sub!(/([a-z.]+)/, "alpha") == mmap
|
|
45
|
-
p $& == "toto"
|
|
46
|
-
p $1 == "toto"
|
|
47
|
-
p mmap.index("toto") == nil
|
|
48
|
-
p mmap.index("alpha") == PAGESIZE
|
|
49
|
-
p mmap.size == 5 + 2 * PAGESIZE
|
|
50
|
-
mmap.gsub!(/\0/, "X")
|
|
51
|
-
p mmap.size == 5 + 2 * PAGESIZE
|
|
52
|
-
|
|
53
|
-
File.delete("aa")
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Installation
|
|
57
|
-
|
|
58
|
-
Install the gem and add to the application's Gemfile by executing:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
bundle add mmap-ruby
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
gem install mmap-ruby
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Development
|
|
71
|
-
|
|
72
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests.
|
|
73
|
-
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
74
|
-
|
|
75
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
|
76
|
-
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
|
77
|
-
push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
78
|
-
|
|
79
|
-
## Contributing
|
|
80
|
-
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[joshuay03]/mmap-ruby. This project is
|
|
82
|
-
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
|
83
|
-
[code of conduct](https://github.com/[joshuay03]/mmap-ruby/blob/main/CODE_OF_CONDUCT.md).
|
|
84
|
-
|
|
85
|
-
## License
|
|
86
|
-
|
|
87
|
-
The gem is available as open source under the terms of the [Ruby license](https://www.ruby-lang.org/en/about/license.txt).
|
|
88
|
-
|
|
89
|
-
## Code of Conduct
|
|
90
|
-
|
|
91
|
-
Everyone interacting in the MmapRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to
|
|
92
|
-
follow the [code of conduct](https://github.com/[joshuay03]/mmap-ruby/blob/main/CODE_OF_CONDUCT.md).
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/mmap-ruby/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "mmap-ruby"
|
|
7
|
-
spec.version = MmapRuby::VERSION
|
|
8
|
-
spec.authors = ["Guy Decoux", "Aaron Patterson", "Joshua Young"]
|
|
9
|
-
spec.email = ["ts@moulon.inra.fr", "tenderlove@github.com", "djry1999@gmail.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "mmap wrapper for Ruby"
|
|
12
|
-
spec.homepage = "https://github.com/joshuay03/mmap-ruby"
|
|
13
|
-
spec.license = "https://www.ruby-lang.org/en/about/license.txt"
|
|
14
|
-
spec.required_ruby_version = ">= 3.3.0"
|
|
15
|
-
|
|
16
|
-
spec.metadata["documentation_uri"] = "https://joshuay03.github.io/mmap-ruby/"
|
|
17
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
|
18
|
-
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
19
|
-
|
|
20
|
-
spec.files = Dir["lib/**/*", "ext/**/*", "**/*.{gemspec,md,txt}"]
|
|
21
|
-
spec.require_paths = ["lib"]
|
|
22
|
-
spec.extensions = ["ext/mmap_ruby/extconf.rb"]
|
|
23
|
-
end
|