Why is pre-allocating done?
조회 수: 1 (최근 30일)
이전 댓글 표시
In a program why is pre-allocating done?for example using arrays of zeros
ex- A=zeros(3)
댓글 수: 0
채택된 답변
Yongjian Feng
2021년 6월 30일
Hello Priya,
This is more like setting default values. Just in case, they are not set in some code paths, the default values will be there.
Thanks,
Yongjian
댓글 수: 0
추가 답변 (1개)
Steven Lord
2021년 6월 30일
Imagine you were building a home. Which would be preferable?
- Buy a lot large enough to build the entire home.
- Build the bathroom.
- Build the bedroom.
- Build the kitchen.
- etc.
or
- Buy a lot large enough to build the bathroom.
- Build the bathroom.
- Buy a new lot large enough to hold the bathroom and a bedroom.
- Move the bathroom to the new lot.
- Build the bedroom.
- Buy a new lot large enough to hold the bathroom, a bedroom, and a kitchen.
- Move the bathroom and the bedroom to the new lot.
- Build the kitchen.
- etc.
Moving a building is hard. Ideally you don't do it, or you do it as few times as you can.
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!