Variable Sized Arrays vs calloc in C

前端 未结 5 1980
挽巷
挽巷 2020-12-03 06:37

On the discussion of dynamic memory here: \"Intro to C Pointers and Dynamic Memory\"

The author states:

A memory block like this can effective

5条回答
  •  青春惊慌失措
    2020-12-03 07:00

    Using variable sized arrays on the stack as an auto variable (instead of the heap using calloc/malloc/new/etc) is not a bad idea for a process that is going to run for a long time and will need to make and destroy lots of little arrays. This is because the stack is guaranteed not to ever become fragmented, while memory can and will get fragmented. If you are writing firmware or a service that needs to run for years without stopping, you are almost prohibited from using malloc or new.

提交回复
热议问题