1.malloc
malloc() allocates size bytes and returns a pointer to the allocated memory. The
memory is not cleared. If size is 0, then malloc() returns either NULL, or a
unique pointer value that can later be successfully passed to free().
2.realloc
realloc() changes the size of the memory block pointed to by ptr to size bytes.
The contents will be unchanged to the minimum of the old and new sizes; newly
allocated memory will be uninitialized. If ptr is NULL, then the call is equiva-
lent to malloc(size), for all values of size; if size is equal to zero, and ptr is
not NULL, then the call is equivalent to free(ptr). Unless ptr is NULL, it must
have been returned by an earlier call to malloc(), calloc() or realloc(). If the
area pointed to was moved, a free(ptr) is done.
3.calloc
calloc() allocates memory for an array of nmemb elements of size bytes each and
returns a pointer to the allocated memory. The memory is set to zero. If nmemb
or size is 0, then calloc() returns either NULL, or a unique pointer value that
can later be successfully passed to free().
4.memalign
The obsolete function memalign() allocates size bytes and returns a pointer to the
allocated memory. The memory address will be a multiple of boundary, which must
be a power of two.
5.valloc
The obsolete function valloc() allocates size bytes and returns a pointer to the
allocated memory. The memory address will be a multiple of the page size. It is
equivalent to memalign(sysconf(_SC_PAGESIZE),size).
6.brk/sbrk
brk() and sbrk() change the location of the program break, which defines the end
of the process's data segment (i.e., the program break is the first location after
the end of the uninitialized data segment). Increasing the program break has the
effect of allocating memory to the process; decreasing the break deallocates mem-
ory.
brk() sets the end of the data segment to the value specified by addr, when that
value is reasonable, the system has enough memory, and the process does not exceed
its maximum data size (see setrlimit(2)).
sbrk() increments the program's data space by increment bytes. Calling sbrk()
with an increment of 0 can be used to find the current location of the program
break.
7.mmap
void *mmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
int munmap(void *addr, size_t length);
mmap() creates a new mapping in the virtual address space of the calling process.
The starting address for the new mapping is specified in addr. The length argu-
ment specifies the length of the mapping.
If addr is NULL, then the kernel chooses the address at which to create the map-
ping; this is the most portable method of creating a new mapping. If addr is not
NULL, then the kernel takes it as a hint about where to place the mapping; on
Linux, the mapping will be created at a nearby page boundary. The address of the
new mapping is returned as the result of the call.
8.alloca
The alloca() function allocates size bytes of space in the stack frame of the
caller. This temporary space is automatically freed when the function that called
alloca() returns to its caller.
9.free
free() frees the memory space pointed to by ptr, which must have been returned by
a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr)
has already been called before, undefined behavior occurs. If ptr is NULL, no
operation is performed.
(To be continued)