zoukankan      html  css  js  c++  java
  • 内存相关函数

    总是记不住内存相关函数的API,特此记录。

    1. malloc

    void* malloc (size_t size);

    Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
    The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.

    2. free

    void free (void* ptr);

    A block of memory previously allocated by a call to malloccalloc or realloc is deallocated, making it available again for further allocations.
    If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior.
    If ptr is a null pointer, the function does nothing.

    3. memcpy

    void * memcpy ( void * destination, const void * source, size_t num );

    Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.

    4. memmove

    void * memmove ( void * destination, const void * source, size_t num );

    Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.

    5. realloc

    void* realloc (void* ptr, size_t size);

    Changes the size of the memory block pointed to by ptr.

    The function may move the memory block to a new location (whose address is returned by the function).

    The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate.

    In case that ptr is a null pointer, the function behaves like malloc, assigning a new block of size bytes and returning a pointer to its beginning.

    6. calloc

    void* calloc (size_t num, size_t size);

    Allocates a block of memory for an array of num elements, each of them size bytes long, and initializes all its bits to zero.

    7. memset

    void * memset ( void * ptr, int value, size_t num );

    Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).

  • 相关阅读:
    iScroll.js 用法参考
    行内元素和块级元素
    struct和typedef struct彻底明白了
    C/C++语法知识:typedef struct 用法详解
    不是技术牛人,如何拿到国内IT巨头的Offer (转载)
    笔试客观题-----每天收集一点点
    <C++Primer>第四版 阅读笔记 第一部分 “基本语言”
    <C++Primer>第四版 阅读笔记 第四部分 “面向对象编程与泛型编程”
    <C++Primer>第四版 阅读笔记 第三部分 “类和数据抽象”
    <C++Primer>第四版 阅读笔记 第二部分 “容器和算法”
  • 原文地址:https://www.cnblogs.com/gattaca/p/6897202.html
Copyright © 2011-2022 走看看