C + + memory management

Source: Internet
Author: User
Reference:

How to implement a malloc:http://blog.jobbole.com/75656/elaborate on the 10 differences between New and malloc: http://www.linuxidc.com/Linux/2016-01/127591.htm

The prototype of malloc in C Libarariy: http://www.cplusplus.com/reference/cstdlib/malloc/

C Dynamic memory Management

void *malloc (size_t size), which requests a size bytes (bytes) of memory to the system, successfully returns a void* pointer (because the requested memory area is untyped, uninitialized), points to the first address, fails to return a null pointer, The size=0 return value depends on the library implementation. Using the requested memory to construct the object requires the void* pointer to be cast as a corresponding pointer, such as CHAR*P = (char *) malloc (100)) (100 bytes), and how many char does this 100 byte create? A char *p= (char*) malloc (100*sizeof (char)) can be used to request 100 char memory.

C + + memory management

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.