Dynamic vs. Static Allocation: How to Coordinate Resource Utilization

Linked lists do not necessarily require the use of dynamic memory allocation. In fact, linked lists can also be implemented using arrays, that is, static memory allocation. For example, you can first define an array containing 100 nodes, and then combine them into a linked list. If you already know that the number of nodes is 100, it may be better to use an array, because it does not require additional pointers to maintain node relationships, and can directly access arbitrary elements.

However, in many cases, you don't know how many nodes there will be in the linked list. In this case, allocating a fixed number of node pools will cause waste or shortage of resources. Therefore, dynamic allocation of memory becomes a solution, which can allocate memory when needed and release memory when not needed.

The essence of dynamic memory allocation is to allocate memory when needed and release memory when not needed. Analogous to examples in life, we can also see similar situations. There are some things we don’t use very often, and buying them to store at home is a waste of money and takes up space, so it’s better to borrow them for use. In a company, different numbers of human resources are needed. If the maximum number of people is hired, many people are often idle fishing, resulting in a waste of company resources, so outsourcing or informal employment (dispatch) has become a solution , to supplement human resources.

It should be noted that dynamic allocation is only a partial allocation of static allocation on a larger level, rather than increasing or decreasing the entire resource. Therefore, the purpose of dynamic allocation is to coordinate and coordinate resources in order to achieve effective utilization of resources as a whole.


d54d48f9dd12f91bc497573a63d475ab.jpeg


It just so happens that I have a C language package here, private message me to get it

Guess you like

Origin blog.csdn.net/m0_67034740/article/details/129708502