필터 지우기
필터 지우기

De-allocation un-used spalloc

조회 수: 1 (최근 30일)
Pete sherer
Pete sherer 2018년 2월 6일
댓글: Jan 2018년 2월 6일
Hi
For the S = spalloc(m,n,nz); function where users can pre-allocate non-zero elements, I wonder if there's a way to de-allocate unused elements. For example S = spalloc( 100000, 500, 2e6); and I only allocate 1e6 element. Is there away to shrink down S to only 1e6 elements?
Thanks

답변 (2개)

Jan
Jan 2018년 2월 6일
편집: Jan 2018년 2월 6일
I'd try it by:
S = spalloc( 100000, 500, 2e6);
... fill in 1e6 values
T = spalloc( 100000, 500, 1e6);
T = S;
Inside the mex level you could use mxRealloc to shrink the reserved block of memory for the data and indices, but even then it is not guaranteed, that the same start address is used or that the free'd part of the memory is given back to the operating system directly or later. Therefore I assume the creation of a new smaller array and copy of the values is not very much worse. But if you are very low on memory, the temporary creation of another array is a problem.

Pete sherer
Pete sherer 2018년 2월 6일
Also would nnz() or numel() provide actual #elements used?
  댓글 수: 1
Jan
Jan 2018년 2월 6일
Please do not post new questions in the section for answers.
You can simply try it. nnz counts the non-zero values, while numel concerns the number of elements or the full matrix.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by