preallocate array without initializing
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ian
el 30 de Nov. de 2018
Comentada: Walter Roberson
el 2 de Dic. de 2018
Is there any way to preallocate a matrix without initializing it to either NaN's, zeros or ones?
I'm working with large image data, typically 1-4 billion pixels, and need to preallocate the array so I can read the data in in chunks. I don't need the array initialized because I will either fill the entire array if reading the data is successful, or throw an exception if it fails.
Preallocating the array with either zeros or NaN's takes matlab several seconds to initialize the array.
Allocating a large array like this in C++ returns immediately because it neither new(...) or malloc(...) bother to initialize the memory.
Is it possible to allocate the array either in a C++ mex file or using coder.ceval(...) to avoid the initialization time?
0 comentarios
Respuesta aceptada
Steven Lord
el 30 de Nov. de 2018
If you want a matrix of class int16 filled with 0 elements, don't wrap a call to zeros in a call to int16. Instead use the typename input listed on the documentation page for the zeros function.
z = zeros(1e4, 1e5, 'int16');
Are you trying to read in a sequence of images that may take up more memory than you have avaialble (or a significant fraction of your available memory?) If so consider creating a tall array from an ImageDatastore and performing your analysis on the tall array. See this documentation page for more information on tall and datastore arrays.
8 comentarios
Walter Roberson
el 2 de Dic. de 2018
Some history . I have not found anything definitive as to when Demand Zero was introduced . Demand paging dates to 1961.
Demand Zero requires MMU which were not present in the intel 80* series until the 80286
https://sigops.org/sosp/sosp15/history/04-satya-slides.pdf
https://homes.cs.washington.edu/~arvind/cs422/lectureNotes/l16-2.pdf
Más respuestas (4)
Bruno Luong
el 30 de Nov. de 2018
Editada: Bruno Luong
el 30 de Nov. de 2018
MEX can do that, use for example this utility
0 comentarios
per isakson
el 30 de Nov. de 2018
Editada: per isakson
el 30 de Nov. de 2018
Try this
>> A(100,100) = 0;
>> whos A
Name Size Bytes Class Attributes
A 100x100 80000 double
I believe it is described by UndocumentedMatlab, but don't find it now. However, see the two first comments to the blog piece, which I linked to.
Maybe, more relevant
>> B(100,100)=uint8(0);
>> whos B
Name Size Bytes Class Attributes
B 100x100 10000 uint8
0 comentarios
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!