当前位置:网站首页>Malloc C language
Malloc C language
2022-07-29 03:40:00 【SHolmes1854】
page 101
the standard library provides analogous functions called malloc and free that have no such restrictions;
page 167
the functions malloc and calloc obtain blocks of memory dynamically.
void *malloc( size_t n)
returns a pointer to n bytes of uninitialized storage, or NULL if the request can not be satisfied.
void *calloc( size_t n, size_t size)
returns a pointer to enough space for an array of n objects of the specified size, or NULL if the request cannot be satisfied. The storage is intialized to zero.
The pointer returned by malloc or calloc has the proper alignment for the object in question, but it must be cast into the appropriate type, as in
int *ip;
ip = ( int * ) calloc ( n ,sizeof( int ) );
free (p) frees the space pointed to by p, where p was originally obtained by a call to malloc or calloc. There are no restrictions on the order in which space is freed, but it is a ghastly error to free something not obtained by
calling calloc or malloc.
It means c Standard library files stdlib.h It has malloc function
Its function definition is like this :
void *malloc( size_t size)
From this we can see , The return value of this function is null pointer type . This pointer points to the memory space allocated according to our needs , If the request fails ( That is, if the space allocation fails ) return NULL.
The following example says
str = ( char * ) malloc( 15 );
Distribution 15byte Space , then malloc The function returns a pointer to this 15byte Spatial void*, Null pointer type . Then cast the type to char * type
Two pictures are from https://www.tutorialspoint.com/c_standard_library/c_function_malloc.htm
边栏推荐
- Understanding of p-type problems, NP problems, NPC problems, and NP hard problems in natural computing
- 【redis系列】字符串数据结构
- 通过递归实现多级联动
- Precautions for using latex
- 安装抓包证书
- RHCE的at,crontab的基本操作,chrony服务和对称加密和非对称加密
- Code speed optimization
- 5年多工作经验,工资给15k,要是你,你会接受吗?
- Introduction to JVM foundation I (memory structure)
- What you see and think in Microsoft
猜你喜欢
I.MX6U-驱动开发-2-LED驱动
Machine learning based on deepchem
[technology 1]
Android view system and custom view Series 1: (kotlin version)
【科技1】
KNN method predicts pregnancy, KNN principle simple code
ROS - create workspace
最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
VISO fast rendering convolution block
随机推荐
Simple code implementation of decision tree
Learn exkmp again (exkmp template)
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
RTP 发送 和接收 h265
安装抓包证书
Various minor problems of jupyter notebook, configuration environment, code completion, remote connection, etc
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
How do programmers use code to completely end those things in the system?
VISO fast rendering convolution block
Rdkit I: using rdkit to screen the structural characteristics of chemical small molecules
Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules
无法一次粘贴多张图片
【科技1】
Simple understanding of CDN, SDN and QoS
1.5 nn. Module neural network (III)
腾讯云使用pem登录
(nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
Introduction to static routing and dynamic routing protocols OSPF and rip and static routing configuration commands
Matlab learning - accumulation of small knowledge points
机器学习【Numpy】