Does MATLAB split up large arrays in memory?

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 Commenti

James Tursa
James Tursa il 28 Ott 2020
Modificato: James Tursa il 28 Ott 2020
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.
@James Tursa, thank you for your response. I'll proceed forward with this assumption.

Accedi per commentare.

Risposte (1)

Bruno Luong
Bruno Luong il 26 Ott 2020
No

7 Commenti

Regarding your flag ("Ambiguous, unhelpful, and obnoxious answer. The answer is probably wrong too but I cant be sure because of the ambiguity."):
It is not ambiguous: you asked the question if Matlab splits up large array in memory. The answer is no. If the answer is unclear to you, feel free to post a comment.
Also, the maximum array size reported by memory looks like 5GB, not 5MB.
Thank you for catching my mistake.
Just to expand on Bruno's concise answer... Nooooooooo.
@John D'Errico, thank you for your elloquent and dramatic expansion of the original answer
@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 il 28 Ott 2020
Modificato: Eric Stevens il 28 Ott 2020
@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.
[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

Accedi per commentare.

Richiesto:

il 26 Ott 2020

Commentato:

il 29 Ott 2020

Community Treasure Hunt

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

Start Hunting!

Translated by