In which segment is memory for library functions allocated?

The way automatic variables/local variables go on to stack,dynamically allocated objects/data type go on to heap; where is the memory for library function calls (say printf()) allocated. In which segment?


Static linking

For a statically linked program, library code is merged in with the application and almost all of the distinction between program and library is lost, ie, each object ends up in the same section that a similar object in the main program would occupy.

Dynamic linking

For dynamically linked programs, if an object is writable and not automatic then memory pages will be allocated in each process that uses the library and a data section (or sections) will exist just for the dynamically loaded libraries.

Auto

Automatic variables are allocated on the stack in the same way for the main program, statically linked library functions, and dynamic libs. The linking process doesn't have any role in this, rather, the generated code simply subtracts a specific amount from the stack pointer for each routine's local automatic space requirements.

Local non-auto

Local static variables are allocated by the linker in the way as module-static and global addresses, they just don't have globally linkable names.

Heap

Finally, library routines will link with the same malloc() (or whatever) and so all heap allocations will be made in the same way from the same group of addresses.


库函数的处理方式与其他链接模块的处理方式不同:它们的局部变量使用堆栈,动态分配的内存部分堆放在堆上。

链接地址: http://www.djcxy.com/p/79900.html

上一篇: C函数内存分配

下一篇: 哪个段是分配库函数的内存?