IOS--DAY03---Memory allocation dynamic RAM allocation

Source: Internet
Author: User

Memory: Divided into five regions

    • The stack area-----------system allocations and reclaims memory. The variables created in the function body exist in the stack area
    • Heap areas are------------allocated and recycled by users, and if a user forgets to recycle, the heap memory is reclaimed by the system if the memory is not sufficient and the program exits
    • Constant area-------------The area of memory used to hold constants
    • Static area-------------variables defined in the function body, the system opens up space, the program has been in operation for a long time, until the program exits, the system is recycled
    • Code Area----------------storing code compilation results

---------------------------------------------------------------------------------

malloc function

void *malloc (unsigned int size);

The malloc function allocates a size contiguous memory space to the system but does not clear the allocated space by 0

Free ();//Release memory

-----------------------------------

void *calloc (unsigned n,unsigned size);

Allocate n sizes of size space

Unlike malloc, the memory space requested by Calloc is initialized to 0;

----------------------------------

void *realloc (void *p, unsigned newSize);

Re-allocating memory at new length

All three of these are released using free

------------------------------------------

Memory manipulation functions

void *memset (void *s, int c, size_t N);

memset (p,0,sizeof (Student));

s begins, all bytes of length n are assigned C;

Usually used for clear structure or array data

void *memcpy (void *dest,const void *source,size_t n);

Copy n bytes from source to Dest

int memcmp (const void *buf1,const void *buf2,unsigned int count);

The above memory manipulation functions can be used for heap memory pages that can be used for stack memory

IOS--DAY03---Memory allocation dynamic RAM allocation

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.