Does MATLAB split up large arrays in memory?

1 次查看(过去 30 天)
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 个评论
James Tursa
James Tursa 2020-10-28
编辑:James Tursa 2020-10-28
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 2020-10-28
@James Tursa, thank you for your response. I'll proceed forward with this assumption.

请先登录,再进行评论。

回答(1 个)

Bruno Luong
Bruno Luong 2020-10-26
No
  7 个评论
Eric Stevens
Eric Stevens 2020-10-28
编辑:Eric Stevens 2020-10-28
@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 2020-10-29
[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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by