MATLAB Answers

Does MATLAB split up large arrays in memory?

59 views (last 30 days)
Eric Stevens
Eric Stevens on 26 Oct 2020 at 18:19
Commented: Walter Roberson on 29 Oct 2020 at 1:39
I am using a C library that expects type LPVOID. I am passing large arrays of uint8 objects. Somewhere around the 5 MB input mark the library function stops processing the array. It seems that this could happen if MATLAB has some optimization that splits large arrays up to avoid having to find large contiguous blocks of memory. My question is: does this happen? Does MATLAB split large arrays or, when I allocate a 10 MB numeric array is it gaurenteed to be contiguous?

  2 Comments

James Tursa
James Tursa on 28 Oct 2020 at 18:35
MATLAB does not split up numeric/logical/char array data memory. All such created array data areas are guaranteed to be contiguous. The non-zero values of sparse arrays are also guaranteed to be contiguous. The caveat to this is that in R2017b and earlier the real and imag data are in separate memory blocks, whereas in R2018a and later the real and imag data are interleaved in one memory block.
Eric Stevens
Eric Stevens on 28 Oct 2020 at 18:44
@James Tursa, thank you for your response. I'll proceed forward with this assumption.

Sign in to comment.

Answers (1)

Bruno Luong
Bruno Luong on 26 Oct 2020 at 18:21
No

  7 Comments

Show 4 older comments
Bruno Luong
Bruno Luong on 28 Oct 2020 at 20:28
@John LOL
Sorry Eric if my short answer seems rude to you.
People who frequent here know that english and making a long nice phare sentence is not my strength. I usually post only pertinent information, often so less but never more.
Eric Stevens
Eric Stevens on 28 Oct 2020 at 21:56
@Bruno Luong, I appreciate your explanation. I am new to the community and unfamiliar with your contributions, so I apologize if I misinterpreted your intent. Such a short answer is hard to take seriously (although I now believe you are correct). James Tursa's comment, while short, is explicit, specific, and inspires confidence.
Walter Roberson
Walter Roberson on 29 Oct 2020 at 1:39
[begin quote]
The most common data type in MATLAB is the complex double-precision, nonsparse matrix. These matrices are of type double and have dimensions m-by-n, where m is the number of rows and n is the number of columns. The data is stored as a vector of interleaved, double-precision numbers where the real and imaginary parts are stored next to each other. The pointer to this data is referred to as pa (pointer to array). To test for a noncomplex matrix, call mxIsComplex.
Before MATLAB Version 9.4 (R2018a), MATLAB used a separate storage representation. The data is stored as two vectors of double-precision numbers—one contains the real data and one contains the imaginary data. The pointers to this data are referred to as pr (pointer to real data) and pi (pointer to imaginary data), respectively. A noncomplex matrix is one whose pi is NULL. However, to test for a noncomplex matrix, call mxIsComplex.
[end quote]
This is explicit. Storage for numeric data is completely continguous now even for complex data; for R2017b and earlier, storage for the real part of numeric data was separated from the complex part (when the complex part existed at all.)
The answer is different for the structured data types such as struct and table and cell array.
Bruno's answer was correct

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!