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!