C Language: malloc and free

Source: Internet
Author: User

1. malloc and free in C language are standard library functions in C language, used to apply for dynamic memory and release memory. -Manage dynamic memory

2. For non-Internal data objects, the use of maloc/free alone cannot meet the requirements of dynamic objects. The constructor must be automatically executed when the object is created, and the Destructor must be automatically executed before the object is extinct. Because malloc/free is a library function rather than an operator and is not controlled by the compiler, it is impossible to impose the tasks of executing constructor and destructor on malloc/free.

3. Notes for using malloc and free:
Malloc requires support for the header file library function.
Malloc allocates a piece of memory.
Malloc is allocated with a memory area, which can be accessed with pointers and moved inside.

That is
Malloc is a function that can overwrite
Malloc only allocates memory, free only recycles memory

More directly, you can use malloc to dynamically apply for memory blocks in c.
So static application memory block?
It can be implemented when a variable is declared or the output is
Char a (10)

Declare a variable array a (10) and apply for 10 Static Memory Spaces
{Basic knowledge:
One Variable occupies 1 memory block
An integer constant occupies 2 memory blocks.
A floating point constant occupies 4 memory blocks}

Author "LinuxLeon"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.