惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

博客园 - 悠然小调

nothing.... Ogre中在SceneNode节点旁显示二维字的代码 博文阅读密码验证 - 博客园 最简单的智能指针原理 模板的特化 计算基类虚表指针在派生类中的偏移量 [转]来自 COM 经验的八个教训 COM本质论学习笔记(一)IDL winsock中select的作用 windows核心编程学习笔记(三)线程池(Thread Pooling) windows核心编程学习笔记(八)结构化异常处理(Structured Exception Handling) [转]亲密接触VC6.0编译器 windows核心编程学习笔记(七)DLL Injection and API Hooking windows核心编程学习笔记(五.续)堆 windows核心编程学习笔记(五)内存映射文件 windows核心编程学习笔记(四)windows内存结构/虚拟内存/线程的堆栈 windows核心编程学习笔记(二)Wait For Kernel Object(s) windows核心编程学习笔记(一)使用Critical Section [转]筛选法求素数
写一个内存拷贝函数
悠然小调 · 2008-03-16 · via 博客园 - 悠然小调

这个是我写的,着重于错误检查和拷贝的正确性,效率远远不如CRT的

// 考虑重叠的状况
void* _memcpy(void* dest, void* src, int len)
{
    
if(!dest || !src || !len || dest == src)
        
return dest;char* pdest = static_cast<char*>(dest);
    
char* psrc = static_cast<char*>(src);// dest 在 src + len 范围内
    if(pdest > psrc && pdest < (psrc + len))
    {
        
// 先备份被覆盖部分
        int need = psrc + len - pdest;
        
int offset = pdest - psrc;
        
char* pcache = new char[need];int i = 0;
        
for (i = 0; i < need; ++i)
            pcache[i] 
= psrc[offset + i]; // 拷贝起始部分
        for (i = 0; i < offset; ++i)
            pdest[i] 
= psrc[i];
        
        
// 拷贝剩余部分
        for (i = 0; i < need; ++i)
            pdest[offset 
+ i] = pcache[i]; 

        delete[] pcache;
    }

else
    {
        
for (int i = 0; i < len; ++i)
            pdest[i] 
= psrc[i];
    }
return dest;
}