c++ - Best practices of dynamic vs. static memory in terms of cleanliness and speed -
I have an array, which is called X, whose size is 6 * size (float). I know that I am declaring:
float x [6];
The stack will allocate 6 * size (float) to X in the memory. However, if I do the following:
float * x; // class definition x = new float [6]; // Delete constructor in class [] x; // I will assign the dynamic memory of 6 * sizeof (float) in class destructor x if x does not change the size of x for the life of the class, then the cleanliness and speed In the case of best practices for (I deliberately miss, if not true, then stack memory operations are faster than dynamic memory operations), should I ensure that X is dynamically stable from allocated memory? thank you in advanced.
Declaring the array of fixed size will definitely be faster for each separate dynamic allocation one empty It is necessary to find the block and it is not very fast.
So if you really care about speed (inherent) rules, if you do not need dynamic allocation - do not use it. If you need it - think twice to allocate after re-allocation is not too fast too.
Comments
Post a Comment