1.16 <GMappedFile>

Structure: <GMappedFile>

The <GMappedFile> represents a file mapping created with mapped-file:new. It has only private members and should not be accessed directly.

Procedures

Method: mapped-file:free self
Method: free self

This call existed before <GMappedFile> had refcounting and is currently exactly the same as mapped-file:unref.

self

Passed: a <GMappedFile>.

a <GMappedFile>

Method: mapped-file:get-bytes self ⇒ %return
Method: get-bytes self ⇒ %return

Creates a new <GBytes> which references the data mapped from self. The mapped contents of the file must not be modified after creating this bytes object, because a <GBytes> should be immutable.

self

Passed: a <GMappedFile>.

a <GMappedFile>

%return

Returned: a <GBytes>.

A newly allocated <GBytes> referencing data from self

Method: mapped-file:get-contents self ⇒ %return
Method: get-contents self ⇒ %return

Returns the contents of a <GMappedFile>.

Note that the contents may not be zero-terminated, even if the <GMappedFile> is backed by a text file.

If the file is empty then #f is returned.

self

Passed: a <GMappedFile>.

a <GMappedFile>

%return

Returned: a string, or #f.

the contents of self, or #f.

Method: mapped-file:get-length self ⇒ %return
Method: get-length self ⇒ %return

Returns the length of the contents of a <GMappedFile>.

self

Passed: a <GMappedFile>.

a <GMappedFile>

%return

Returned: an unsigned 64-bit integer.

the length of the contents of self.

Procedure: mapped-file:new filename writable ⇒ %return

Maps a file into memory. On UNIX, this is using the mmap() function.

If writable is #t, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.

Note that modifications of the underlying file might affect the contents of the <GMappedFile>. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. using file-set-contents?).

If filename is the name of an empty, regular file, the function will successfully return an empty <GMappedFile>. In other cases of size 0 (e.g. device files such as /dev/null), error will be set to the <%GFileError> value inval.

filename

Passed: a file name, as a string.

The path of the file to load, in the GLib filename encoding

writable

Passed: a boolean.

whether the mapping should be writable

%return

Returned: a <GMappedFile>.

a newly allocated <GMappedFile> which must be unref’d with mapped-file:unref, or #f if the mapping failed.

Procedure: mapped-file:new-from-fd fd writable ⇒ %return

Maps a file into memory. On UNIX, this is using the mmap() function.

If writable is #t, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.

Note that modifications of the underlying file might affect the contents of the <GMappedFile>. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. using file-set-contents?).

fd

Passed: a 32-bit integer.

The file descriptor of the file to load

writable

Passed: a boolean.

whether the mapping should be writable

%return

Returned: a <GMappedFile>.

a newly allocated <GMappedFile> which must be unref’d with mapped-file:unref, or #f if the mapping failed.

Method: mapped-file:ref self ⇒ %return
Method: ref self ⇒ %return

Increments the reference count of self by one. It is safe to call this function from any thread.

self

Passed: a <GMappedFile>.

a <GMappedFile>

%return

Returned: a <GMappedFile>.

the passed in <GMappedFile>.

Method: mapped-file:unref self
Method: unref self

Decrements the reference count of self by one. If the reference count drops to 0, unmaps the buffer of self and frees it.

It is safe to call this function from any thread.

Since 2.22

self

Passed: a <GMappedFile>.

a <GMappedFile>