C + + memory Manager

Source: Internet
Author: User
Tags garbage collection

The C Standard library provides the Malloc,free,calloc,realloc,c++ standard library also provides new, new[], delete, delete[]. These are used to manage memory, it seems enough, why do you have to write a memory manager?

The reason is also the performance considerations: for example, malloc and new are for versatility and can handle multithreaded situations (multithread). For single-threaded programs, this additional functionality degrades performance.
It is also noted that the New/delete/free/malloc are to be switched between User-space and Kernel-code, and the context switch will degrade performance. If you write a User-land memory manager, you can drastically reduce this switch. There is also the GC (garbage collection).

Several requirements
    1. Speed: Faster than the compiler's memory allocator
    2. Robust: cannot have memory leaks, allocate as much as you can recover
    3. Convenience: The user does not need to change the code, can add memory manager in
    4. Porting: should be cross-platform, user on what system can be used, easy to transplant
Previous experience
    1. Request Chunk Memory
      One-time application of a large chunk of memory, reduce the number of applications to the system, the need to apply for memory in the future from this large allocation.
      (That's not the cache.) )
    2. Optimized for specific dimensions
      One of the most common memory request sizes in any program. Optimize for this size and improve performance.
    3. Memory that needs to be removed is temporarily stored in the container (appreciating)
      From the user's point of view, the variable declaration period ends and the allocated memory is freed, but the memory manager can actually "not really return this memory to the system", but rather save it for the subsequent need to allocate memory. Of course, this kind of memory is more fragmented, so the redistribution may not be enough, then you have to find large chunks of memory to allocate.

The above is from an IBM tutorial, there is a lot of content not to read and understand, dig pit with fill: https://www.ibm.com/developerworks/aix/tutorials/au-memorymanager/index.html

C + + memory Manager

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.