MEMMAPFILE Construct memory-mapped file object.
M = MEMMAPFILE(FILENAME) constructs a memmapfile object that maps file FILENAME
to memory, using default property values. FILENAME can be a partial pathname
relative to the MATLAB path. If the file is not found in or relative to the
current working directory, MEMMAPFILE searches down the MATLAB search path.
M = MEMMAPFILE(FILENAME, PROP1, VALUE1, PROP2, VALUE2, ...) constructs
a memmapfile object, and sets the properties of that object that are
named in the argument list (PROP1, PROP2, etc.) to the given values
(VALUE1, VALUE2, etc.). All property name arguments must be quoted
character vectors or strings (e.g., 'Writable'). Any properties that
are not specified are given their default values.
Property/Value pairs and descriptions:
Format: string scalar or character vector, or Nx3 cell array (defaults to 'uint8').
Format of the contents of the mapped region.
If a string or character vector, Format specifies that the
mapped data is to be accessed as a single vector of type
specified by Format's value. Supported values are 'int8',
'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32',
'uint64', 'single', and 'double'.
If an Nx3 cell array, Format specifies that the mapped data is
to be accessed as a repeating series of segments of basic
types, each with specific dimensions and name. The cell array
must be of the form {TYPE1, DIMS1, NAME1; ...; TYPEn, DIMSn,
NAMEn}, where TYPE is one of the data types listed above, DIMS
is a numeric row vector specifying the dimensions of the
segment of data to use, and NAME is a field name to use to
access the data (as a subfield of the Data property). See Data
property and examples below.
Repeat: Positive integer or Inf (defaults to Inf).
Number of times to apply the specified format to the mapped region of the
file. If Inf, repeat until end of file.
Offset: Nonnegative integer (defaults to 0).
Number of bytes from the start of the file to the start of the mapped
region. Offset 0 represents the start of the file.
Writable: True or false (defaults to false).
Access level which determines whether or not Data property (see below)
may be assigned to.
All the properties above may also be accessed after the memmapfile object has
been created by dot-subscripting the memmapfile object. For example,
M.Writable = true;
changes the Writable property of M to true.
Two properties which may not be specified to the MEMMAPFILE constructor as
Property/Value pairs are listed below. These may be accessed (with
dot-subscripting) after the memmapfile object has been created.
Data: Numeric array or structure array.
Contains the actual memory-mapped data from FILENAME. If Format
is a string or character vector, then Data is a simple numeric
array of the type specified by Format. If Format is a cell
array, then Data is a structure array, the field names of which
are specified by the third column of the cell array. The type
and shape of each field of Data are determined by the first and
second columns of the cell array, respectively. Changes to the
Data field or subfields also change the corresponding values in
the memory-mapped file.
Filename: Char array.
Contains the name of the file being mapped.
Note that when a variable containing a memmapfile object goes out of scope or is
otherwise cleared, the memory map is automatically unmapped.
Examples:
% To map the file 'records.dat' to a series of unsigned 32-bit % integers and
set every other value to zero (in Data and % records.dat):
m = memmapfile('records.dat', 'Format', 'uint32', 'Writable', true);
m.Data(1:2:end) = 0;
% To map the file 'records.dat' to a repeating series of 20 singles % (as a
5-by-4 matrix) called 'sdata', followed by 10 doubles (as a 1-by-10 vector)
called 'ddata':
m = memmapfile('records.dat', 'Format', {'single' [5 4] 'sdata'; ...
'double', [1 10] 'ddata'});
firstSdata = m.Data(1).sdata; firstDdata = m.Data(1).ddata;
See also MEMMAPFILE/DISP, MEMMAPFILE/GET
Documentation for memmapfile
doc memmapfile