Dynamic memory management flexible array

Definition of flexible array: The last element in the structure is an array of unknown data size.

Characteristics of flexible arrays: 1. The flexible array members in the structure must be preceded by at least one other member; 2. The size of the structure returned by sizeof does not include the memory of the flexible array; 3. The structure containing flexible array members uses malloc() The function performs dynamic allocation of memory, and the allocated memory should be larger than the size of the structure to accommodate the expected size of the flexible array.

 

The following is a distinction between the two writing methods:

Advantages of flexible arrays:

1. Facilitates memory release 2. Helps access speed and reduces memory fragmentation. 

There can only be one flexible array in the structure.

Guess you like

Origin blog.csdn.net/2301_77868664/article/details/130897629