Class: SimpleMmap::MappedFile
- Inherits:
-
Object
- Object
- SimpleMmap::MappedFile
- Defined in:
- ext/simple_mmap/mapped_file.c
Defined Under Namespace
Classes: MmapData
Instance Method Summary collapse
-
#close ⇒ Object
munmap() the current mmapped file.
-
#read_window_data(offset, length) ⇒ Object
Read
length
bytes starting atoffset
. -
#size ⇒ Object
Return size of mapped file.
Instance Method Details
#close ⇒ Object
munmap() the current mmapped file
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/simple_mmap/mapped_file.c', line 94
static VALUE sm_mapped_file_close(VALUE vself)
{
VALUE vsm_map;
simple_mmap_map *sm_map;
sm_map = ALLOC(simple_mmap_map);
vsm_map = rb_ivar_get(vself, rb_intern("@mmap_data"));
Data_Get_Struct(vsm_map, simple_mmap_map, sm_map);
if (sm_map->map != (caddr_t) -1)
munmap(sm_map->map, sm_map->len);
if (sm_map->fd != -1)
close(sm_map->fd);
return Qtrue;
}
|
#read_window_data(offset, length) ⇒ Object
Read length
bytes starting at offset
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'ext/simple_mmap/mapped_file.c', line 117
static VALUE sm_mapped_file_read_window_data(VALUE vself, VALUE voffset, VALUE vlength)
{
size_t offset = NUM2INT(voffset);
size_t length = NUM2INT(vlength);
VALUE vsm_map;
simple_mmap_map *sm_map;
vsm_map = rb_ivar_get(vself, rb_intern("@mmap_data"));
Data_Get_Struct(vsm_map, simple_mmap_map, sm_map);
if (offset < 0 || offset > sm_map->len) {
return Qnil;
}
// If the range overflows, return part that overlaps
if ((offset + length) > sm_map->len) {
length = sm_map->len - offset;
}
return rb_str_new(sm_map->map + offset, length);
}
|
#size ⇒ Object
Return size of mapped file
146 147 148 149 150 151 152 153 154 |
# File 'ext/simple_mmap/mapped_file.c', line 146
static VALUE sm_mapped_file_size(VALUE vself)
{
VALUE vsm_map;
simple_mmap_map *sm_map;
vsm_map = rb_ivar_get(vself, rb_intern("@mmap_data"));
Data_Get_Struct(vsm_map, simple_mmap_map, sm_map);
return UINT2NUM(sm_map->len);
}
|