View source code
Display the source code in dmd/common/file.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Struct dmd.common.file.FileMapping
Encapsulated management of a memory-mapped file.
struct FileMapping(Datum)
;
Constructors
Name | Description |
---|---|
this
(filename)
|
Open filename and map it in memory. If Datum is const , opens for
read-only and maps the content in memory; no error is issued if the file
does not exist. This makes it easy to treat a non-existing file as empty.
|
Fields
Name | Type | Description |
---|---|---|
data
|
Datum[] | Memory-mapped array |
handle
|
void | Handle of underlying file |
name
|
const(char)* | Name of underlying file, zero-terminated |
Methods
Name | Description |
---|---|
active
()
|
Queries whether this is currently associated with a file.
|
close
()
|
Frees resources associated with this mapping. However, it does not deallocate the name.
Reinitializes this as a fresh object that can be reused.
|
discard
()
|
Deletes the underlying file and frees all resources associated.
Reinitializes this as a fresh object that can be reused.
|
filename
()
|
Returns the zero-terminated file name associated with the mapping. Can NOT
be saved beyond the lifetime of this .
|
length
()
|
Queries the length of the file associated with this mapping. If not active, returns 0. |
moveToFile
(filename)
|
Unconditionally and destructively moves the underlying file to filename .
If the operation succeeds, returns true. Upon failure, prints a message to
stderr and returns false . In all cases it closes the underlying file.
|
opSlice
()
|
Get a slice to the contents of the entire file. |
resize
(size)
|
Resizes the file and mapping to the specified size .
|
Parameters
Name | Description |
---|---|
Datum | the mapped data type: Use a POD of size 1 for read/write mapping
and a const version thereof for read-only mapping. Other primitive types
should work, but have not been yet tested. |
Authors
Walter Bright, https://www.digitalmars.com
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.