内存相关函数

总是记不住内存相关函数的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 malloc, calloc 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.

时间: 2024-08-03 02:07:07

内存相关函数的相关文章

基本字符串相关函数,基本宏,内存相关函数,类型转换函数实现合集

1.常用宏或函数的实现_T,_L宏:#define unsigned short L#define _T(x)       __T(x)#define _TEXT(x)    __T(x) #ifdef  _UNICODE#define __T(x) L##x     #else#define __T(x) x          #endif #define _L(x) L##x assert宏实现:#define assert(expr)do{    if (!(expr))    {    

C语言动态内存相关函数

C语言动态内存管理函数有4个,分别为malloc,realloc,calloc和free.malloc函数分配一块堆内存:calloc是malloc的变种,功能相同,有细小的差别:realloc修改原内存块大小:free释放参数指针指向的内存块.下面分别介绍它们的函数原型.函数功能和一些特别的注意事项. Function name 函数原型 函数功能 malloc void * malloc ( size_t size ); 向系统申请分配指定size个字节的内存空间.返回类型是 void* 类

c++内存相关函数

memset void *memset(void *s, int ch, size_t n); 函数解释:将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 ch 替换并返回 s . memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法 memcpy 函数原型 void *memcpy(void *destin, void *source, unsigned n); 参数 destin-- 指向用于存储复

菜鸟nginx源码剖析数据结构篇(九) 内存池ngx_pool_t[转]

菜鸟nginx源码剖析数据结构篇(九) 内存池ngx_pool_t Author:Echo Chen(陈斌) Email:[email protected] Blog:Blog.csdn.net/chen19870707 Date:Nov 11th, 2014 今天是一年一度的光棍节,还没有女朋友的程序猿童鞋不妨new一个出来,内存管理一直是C/C++中最棘手的部分,远不止new/delete.malloc/free这么简单.随着代码量的递增,程序结构复杂度的提高.今天我们就一起研究一下以精巧著

菜鸟nginx源码剖析数据结构篇(九) 内存池ngx_pool_t

1.源代码位置 头文件:http://trac.nginx.org/nginx/browser/nginx/src/core/ngx_palloc.h 源文件:http://trac.nginx.org/nginx/browser/nginx/src/core/ngx_palloc.c 2.数据结构定义 先来学习一下nginx内存池的几个主要数据结构:     ngx_pool_data_t(内存池数据块结构) 1: typedef struct { 2:     u_char         

菜鸟nginx源代码剖析数据结构篇(九) 内存池ngx_pool_t

Author:Echo Chen(陈斌) Email:[email protected] Blog:Blog.csdn.net/chen19870707 Date:Nov 11th, 2014 今天是一年一度的光棍节.还没有女朋友的程序员童鞋最好还是new一个出来,内存管理一直是C/C++中最棘手的部分.远不止new/delete.malloc/free这么简单. 随着代码量的递增,程序结构复杂度的提高.今天我们就一起研究一下以静止著称的nginx的内存池. 1.源码位置 头文件:http://

POSIX 共享内存

POSIX共享内存相关函数: shm_open函数 功能:用来创建或打开一个共享内存对象 原型 int shm_open(const char *name, int oflag, mode_t mode); 参数 name:共享内存对象的名字 oflag:与open函数类似,可以是O_RDONLY.O_RDWR,还可以按位或上O_CREAT.O_EXCL.O_TRUNC等. mode:此参数总是需要设置,如果oflag没有指定了O_CREAT,可以指定为0 返回值:成功返回非负整数文件描述符:失

nginx源码学习----内存池

最近在进行监控平台的设计,之前一直觉得C/C++中最棘手的部分是内存的管理上,远不止new/delete.malloc/free这么简单.随着代码量的递增,程序结构复杂度的提高.各种内存方面的问题悄然滋生.而且作为平台,后期的插件扩展在所难免.长时间运行的采集平台的特性更是提出了对稳定性的高要求.不是c#.java,没有虚拟机为你管理内存,一切都要靠自己.于是想看看nginx.python.lua这些C的经典之作在内存管理这块“要地”又是如何处理的. 先来看看nginx吧,因为网上都说nginx

linux进程间通信之Posix共享内存用法详解及代码举例

Posix共享内存有两种非亲缘进程间的共享内存方法:1).  使用内存映射文件,由open函数打开,再由mmap函数把返回的文件描述符映射到当前进程空间中的一个文件. 2). 使用共享内存区对象,由shm_open打开一个 Posix IPC名字.再由mmap把返回的描述符映射到当前进程的地址空间. Posix共享内存相关函数头文件及原型:#include <sys/mman.h>int shm_open(const char *name, int oflag, mode_t mode);功能