ABSTRACT

Memory management is mainly related to memory allocation and release of allocated memory when it is no longer needed. Memory allocation can be performed either statically or dynamically. This chapter focuses on how to allocate memory dynamically during program execution, in order to form flexible data structures, such as linked lists and binary trees. In static memory allocation, the memory is allocated from the stack. The size of the allocated memory is fixed; we must specify its size when writing the program and it cannot change during program execution. In dynamic memory allocation, the memory is allocated from the heap during program execution. The chapter discusses briefly the memcpy(), memmove(), and memcmp() functions that are often used for memory management. To organize data in sorted order, a flexible data structure named tree is typically used. This type of structure is met in several real-life examples, like a family tree, an organizational chart, or a computer's folder system.