The Linux Programming Interface
Memory Allocation
(1) 内容
This chapter describes the functions that are used to allocate memory on the heap or the stack.
To allocate memory, C programs normally use the malloc family of functions, which we describe shortly. However, we begin with a description of brk() and sbrk(), upon which the malloc functions are based.
#include <unistd.h>
int brk(void *end_data_segment);
The brk() system call sets the program break to the location specified by end_data_segment. Since virtual memory is allocated in units of pages, end_data_segment is effectively rounded up to the next page boundary.
On success, sbrk() returns the previous address of the program break.
The call sbrk(0) returns the current setting of the program break without changing it.
(02) malloc()函数,分配内存的使用
The malloc function allocates size bytes from the heap and returns a pointer to the start