memmove是否将动态内存用于其临时数组 [英] Does memmove use dynamic memory for its temporary array

查看:61
本文介绍了memmove是否将动态内存用于其临时数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 C11 N1570标准草案:

7.24.2.2"memmove函数":

7.24.2.2 "The memmove function":

memmove函数将n字符从s2指向的对象复制到s1指向的对象. 进行复制就像是先将s2所指向对象中的n字符首先复制到n字符的临时数组中,该临时数组不与s1所指向的对象重叠和s2,然后将临时数组中的n字符复制到s1

The memmove function copies n characters from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n characters from the object pointed to by s2 are first copied into a temporary array of n characters that does not overlap the objects pointed to by s1 and s2, and then the n characters from the temporary array are copied into the object pointed to by s1

因此,如果我选择使用(file_size = 32K)移动大小为32K的缓冲区

So if I choose to move a buffer of size 32K using (file_size = 32K)

memmove(io_Buffer, io_Buffer+17, file_size);

临时缓冲区的大小不是32K吗?

won't the temp buffer be of size 32K?

问题

程序可以自行分配动态内存吗?它会在那一行中分配和释放内存吗?

Can the program allocate dynamic memory on its own? Does it allocate and free the memory in that one line?

推荐答案

我认为您错过了该句子中的好像".这意味着效果将与执行此操作相同,而不是实际上执行该操作.我从未见过真正使用临时数组的memmove实现.

I think you missed the "as if" in that sentence. That means the effects will be the same as if it did that, not that it will actually do that. I've never seen an implementation of memmove that actually uses a temporary array.

这篇关于memmove是否将动态内存用于其临时数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆