Memory Management-simple allocation Program

Source: Internet
Author: User

AllocateProgramGlobal variables

Allocation program initialization Function

The sbrk () function is used to dynamically increase the memory space.

Char * sbrk (INT incr) incr is the increase in the number of bytes.

Memory Control Block Structure

The release function of the Assignment Program.

Allocation Function of the Assignment Program

The figure between pointers is as follows:

Mem_alloc_ptr is the available range pointer returned by the malloc () function.

Thoughts:

1). The underlying programming skills of memory allocation are forced type conversion and some pointer-to-pointer operations.

2) In this method, 4 bytes are used to identify whether the memory is available, which is a waste.

3) In this method, when the memory is released, there is no memory merging, which will generate a lot of memory fragments.

4) In this method, when the memory is allocated, in the worst case, all the memory blocks need to be traversed, Which is inefficient.

References:

Memory http://www.ibm.com/developerworks/cn/linux/l-memory/

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.