필터 지우기
필터 지우기

estimate memory size in matlab

조회 수: 405 (최근 30일)
sita
sita 2013년 6월 18일
댓글: Bruno Luong 2022년 1월 7일
Hi,
Is there anyway of estimating memory before execution?So that i can cut down my problem size.(out of memory error)
if i try to give x = ones(10^6);
size of x is out of memory.
Please help in this regards.
Thanks, Sita
  댓글 수: 2
James VanderVeen
James VanderVeen 2022년 1월 7일
The memory size in Bytes required by an rectangular array is (# of rows)*(# of cols)*(size of one element).
E.g. Double precision variables are by default 64-bits or 8-bytes
For a double precision array with 25850 rows and colums the memory size is:
format longG
arraysize = 25850*25850*8;
fprintf("The array will need %.0f bytes in memory", arraysize)
The array will need 5345780000 bytes in memory
1 GB is 1024 MB
1 MB is 1024 KB
1 KB is 1024 B
Therefore;
inKB = arraysize/1024;
inMB = arraysize/1024^2;
inGB = arraysize/1024^3;
fprintf("The array will need %.5f KB or %.5f MB or %.5f GB of memory", inKB, inMB, inGB)
The array will need 5220488.28125 KB or 5098.13309 MB or 4.97865 GB of memory
The MATLAB online version I'm using has a maximum array size of 5.0 GB, but if I increase the array to 25851 by 25851, it says I exceed the 5.0 GB limit even though the new array is only 4.9797 GB in size. This appears to mean that there is about 22 MB of data to store information about the array.
Stephen23
Stephen23 2022년 1월 7일

댓글을 달려면 로그인하십시오.

답변 (4개)

Jan
Jan 2013년 6월 18일
편집: Jan 2013년 6월 18일
Notice that ones(10^6) creates a square matrix with 1e6*1e6 = 1e12 elements, which needs a free memory block of 8 TB. So with less than 16 TB free RAM I would not expect this to run reliably.

Chetan Aswathanarayana
Chetan Aswathanarayana 2013년 6월 18일
I' am not sure if we can do this currently without creating a variable. However if the variable is already in the workspace, then the below command would give the bytes allocated.
>>whos x
However you could type the below command, you would then know the maximum memory avaliable in your system
>>memory
This is what I got on my PC:
Maximum possible array: 18848 MB (1.976e+10 bytes) *
Memory available for all arrays: 18848 MB (1.976e+10 bytes) *
Memory used by MATLAB: 1680 MB (1.761e+09 bytes)
Physical Memory (RAM): 12279 MB (1.288e+10 bytes)

Iain
Iain 2013년 6월 18일
The generic size of any variable is:
sum of (each element of the array * bytes in that element) + some overhead.
Normal arrays: Double, uint64 & int64 formats have 8 bytes per element. single, uint32 & int32 formats have 4 bytes per element. some character types, uint16 & int16 formats have 2 bytes per element. logical, most character types, uint8 & int8 formats have 1 byte per element. Overheads are "small" - I think this would be a few 10s of bytes for normal arrays.
Cell arrays and structures are much more detailed and have higher overheads.
  댓글 수: 3
Haiyin Amania
Haiyin Amania 2018년 12월 24일
where do you find this info from ? because I'm still trying to figure out how I can get the data overheads recorded in matlab. thanks.
Bruno Luong
Bruno Luong 2022년 1월 7일
Using C Mex you can find the size by sizeof(MxArray)
It changes from version to version.

댓글을 달려면 로그인하십시오.


Tom
Tom 2013년 6월 18일
Use the MEMORY function.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by