In most language. even a stack-based environment needs some dynamic capabilities in order to handle pointer allocation and de-allocation HEAP the data structure to handle such allocation Allocated as a linear block of memory which provides two operations (1)Allocate, which takes a size parameter and returns a pointer to a block of memory of the correct size, or a null pointer if none exists (2) Free, which takes a pointer to an allocated block of memory and marks it as being free again
• In most language, even a stack-based environment needs some dynamic capabilities in order to handle pointer allocation and de-allocation • HEAP, the data structure to handle such allocation. • Allocated as a linear block of memory, which provides two operations: (1) Allocate, which takes a size parameter and returns a pointer to a block of memory of the correct size, or a null pointer if none exists. (2) Free, which takes a pointer to an allocated block of memory and marks it as being free again
These two operations exist under different names in many languages New and dispose in Pasca New and delete in C++ Malloc and free in the c language a standard method for maintaining the heap and implementing these functions ( 1)Acircular linked list of free blocks (2) Memory is taken by malloc; (3) Memory is return by free The drawbacks (1)The free operation can not tell if the pointer is legal or no (2)Care must be taken to coalesce blocks; otherwise, the heap can quickly become fragmented
• These two operations exist under different names in many languages: New and dispose in Pascal; New and delete in C++; Malloc and free in the C language. • A standard method for maintaining the heap and implementing these functions: (1) A circular linked list of free blocks; (2) Memory is taken by malloc; (3) Memory is return by free. • The drawbacks: (1) The free operation can not tell if the pointer is legal or not; (2) Care must be taken to coalesce blocks; otherwise, the heap can quickly become fragmented