当前位置:网站首页>String function (Part 2)
String function (Part 2)
2022-07-28 11:56:00 【Eight days a week】
One 、memcpy
void * memcpy ( void * destination, const void * source, size_t num );
- function memcpy from source The position of begins to be copied back num Bytes of data to destination Memory location for .
- This function is encountering '\0' It doesn't stop .
- If source and destination There is any overlap , The results of replication are undefined .
Simulation Implementation :
void * memcpy ( void * dst, const void * src, size_t count)
{
void * ret = dst;
assert(dst);
assert(src);
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
return(ret);
}
Two 、memmove
void * memmove ( void * destination, const void * source, size_t num );
- and memcpy The difference is that memmove The source and target memory blocks processed by the function can overlap .
- If the source space and the target space overlap , You have to use memmove Function processing .
void * memmove ( void * dst, const void * src, size_t count)
{
void * ret = dst;
if (dst <= src || (char *)dst >= ((char *)src + count)) {
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
}
else {
/*
* Overlapping Buffers
* copy from higher addresses to lower addresses
*/
dst = (char *)dst + count - 1;
src = (char *)src + count - 1;
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst - 1;
src = (char *)src - 1;
}
}
return(ret);
}边栏推荐
- Object to object mapping -automapper
- async await如何实现并发
- [geek challenge 2019] babysql-1 | SQL injection
- Specific process of strong cache and negotiation cache
- R language uses LM function to build regression model and regression model for transformed data (for example, it is necessary to build regression model for X and y, but they have no linear relationshi
- 保障邮箱安全,验证码四个优势
- Embrace open source guidelines
- Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center
- tolua之wrap文件的原理与使用
- 中国业务型CDP白皮书 | 爱分析报告
猜你喜欢

consul安装与配置

Understand how to prevent tampering and hijacking of device fingerprints
![[geek challenge 2019] babysql-1 | SQL injection](/img/21/b5b4727178a585e610d743e92248f7.png)
[geek challenge 2019] babysql-1 | SQL injection

可视化大型时间序列的技巧。

Are interviews all about memorizing answers?

Lua对table进行深拷贝

Byte side: how to realize reliable transmission with UDP?

Unity 一键替换场景中的物体

Upgrading of computing power under the coordination of software and hardware, redefining productivity

108. Introduction to the usage of SAP ui5 image display control Avatar
随机推荐
LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
Skiasharp's WPF self drawn drag ball (case version)
Article summary of MinGW installation and use
Redis安装
STL concept and its application
一些知识概念
How async await implements concurrency
Multithreading and high concurrency (III) -- source code analysis AQS principle
STL の 概念及其应用
Specific process of strong cache and negotiation cache
Zotero document manager and its use posture (updated from time to time)
Database advanced learning notes - storage structure
MySQL (version 8.0.16) command and description
R language ggplot2 visualization: ggdensity function of ggpubr package visualizes density graph and uses stat_ overlay_ normal_ Density function superimposes positive distribution curve, custom config
consul安装与配置
Alexnet - paper analysis and reproduction
Today's sleep quality record 74 points
Globalthis is not defined solution
R language uses LM function to build regression model, uses the augmented function of bloom package to store the model results in dataframe, and uses ggplot2 to visualize the regression residual diagr
async await如何实现并发