Computer Science, asked by Arulkumaran3690, 10 months ago

Allocating memory statically or dynamically while declaring an array and storing n values in it?Which is more efficient and why?

Answers

Answered by VedantJain
0

Answer: Both will do

Explanation: If you allocate memory statically, the bytes are taken up from the hard drive/VRAM (Virtual RAM). Although this is good for allocating large amounts of data, you have to delete this statically allocated data so that other programs can use it. Moreover, it is a bad coding convention.

If you allocate data dynamically, it takes up space in the RAM/DRAM (SSD Dynamic RAM). Although it is a good coding convention to do so, one should not allocate huge amounts of data dynamically.

To be honest, whatever you use, it does not matter as long as you are not playing with more than about 2^32 bytes of data. The speed is the same.

Similar questions