Ask Your Question
2

What is the process of how malloc is managed during compile time and run time?

asked 2022-01-04 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-05-26 04:00:00 +0000

plato gravatar image

During compile time, the malloc function is included in the code as a symbol that the linker can resolve when the program is compiled. The linker then generates a binary executable that includes the symbol for the malloc function.

During runtime, when the program starts, the operating system allocates a section of memory for the program to use. When a call to malloc is made, the program requests a specific amount of memory from the operating system, which then returns a pointer to the beginning of the allocated memory block. The program then uses this pointer to access and manipulate the data in the allocated memory block.

When the program is finished using the allocated memory, it can free it using the free function. The free function returns the allocated memory block back to the operating system for use by other programs.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-04 11:00:00 +0000

Seen: 19 times

Last updated: May 26 '22