MappedFile.newFromFd

glib.mapped_file.MappedFile newFromFd(int fd, bool writable)

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

If writable is true, 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 [glib.global.fileSetContents]).

Parameters

fdThe file descriptor of the file to load
writablewhether the mapping should be writable

Returns

a newly allocated #GMappedFile which must be unref'd

with [glib.mapped_file.MappedFile.unref], or null if the mapping failed.

Throws

[ErrorWrap]