Đang chuẩn bị liên kết để tải về tài liệu:
C Programming for Scientists & Engineers phần 9
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Mỗi mẫu thử nghiệm chức năng quy định cụ thể chức năng có liên quan sẽ nhận được một trong hai giá trị của một thành viên trong vòng một của dữ liệuChức năng: wrlte_area, sử dụng trong chương trình 5.2. Viết giá trị của khu vực, thông qua chức năng gọi điện thoại theo giá trị, tập tin có tên theo tên tập tin đó là thông qua giá trị. | 6 Dynamic Memory Management and Linked Lists . c provides a collection of functions that allow variables to be created and destroyed whilst a program is running. What this means is that sections of memory can be reserved or allocated and used to store data when required. When the data stored in these locations is no longer required the allocated memory can be released or freed becoming available for possible re-use at some other time. This method of memory management is called dynamic because the c program decides when to use it. In contrast the use of arrays is called static memory management because array sizes are fixed before the program runs. As seen in previous chapters using arrays in programs that may need to process varying amounts of data always carries the risk that the arrays are not big enough to hold all of the data. In large programs this is a serious problem that can be overcome through the use of dynamic memory management. In using dynamic memory management it is typical to design methods of storing data by dynamically creating data structures containing several member variables. Some of these members are used to store the processed data and other members are pointers that can store the addresses of other data structures. Using these pointers as many data structures as required can be chained together forming a linked list. Team-Fl Dynamic memory management and linked lists 115 This chapter presents the essential facilities for dynamic memory management demonstrating them through various examples. Attention then moves on to linked lists and their practical use. 6.2 Essential facilities for dynamic memory management To use any dynamic memory management facilities a c program must include a standard library to provide the necessary function prototypes. This library is either stdlib.h or alloc.h depending on the programming environment being used. c provides the following functions void malloc no_bytes void calloc no_blocks no_bytes void realloc .