How MATLAB Allocates Memory
In this section...
“Memory Allocation for Arrays” on page 29-12
“Data Structures and Memory” on page 29-16
Memory Allocation for Arrays
The following topics provide information on how the MATLAB software allocates memory
when working with arrays and variables. The purpose is to help you use memory more
efficiently when writing code. Most of the time, however, you should not need to be
concerned with these internal operations as MATLAB handles data storage for you
automatically.
- “Creating and Modifying Arrays” on page 29-12
- “Copying Arrays” on page 29-13
- “Array Headers” on page 29-14
- “Function Arguments” on page 29-15
NoteAny information on how the MATLAB software handles data internally is subject to
change in future releases.
Creating and Modifying Arrays
When you assign a numeric or character array to a variable, MATLAB allocates a
contiguous virtual block of memory and stores the array data in that block. MATLAB also
stores information about the array data, such as its class and dimensions, in a separate,
small block of memory called a header.
If you add new elements to an existing array, MATLAB expands the existing array in
memory in a way that keeps its storage contiguous. This usually requires finding a new
block of memory large enough to hold the expanded array. MATLAB then copies the
contents of the array from its original location to this new block in memory, adds the new
elements to the array in this block, and frees up the original array location in memory.
29 Memory Usage