FB_MEMCOPY
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgFBMemcopy
- 最后更新: 2022-06-24
将一块内存从一个位置复制到另一个位置
语法
declare function fb_memcopy cdecl ( byref dst as any, byref src as any, byval bytes as uinteger ) as any ptr用法
[result =] fb_memcopy( dst, src, bytes )参数
dst
目标内存的起始地址。
src
源内存的起始地址。
bytes
要复制的字节数。
返回值
返回目标内存的起始地址。
说明
fb_memcopy 将指定数量的字节从内存位置 src 复制到内存位置 dst。
每个起始地址均取自对变量或数组元素的引用。
内存区域不得重叠(否则,复制操作不保证正确执行,尤其取决于平台)。当内存区域确实重叠时,建议优先使用 fb_memmove(更安全的方式)。
为避免溢出,src 和 dst 所指向的有效内存区域大小必须至少等于要复制的字节数。
源指针和目标指针所指对象的底层类型与该函数无关。
该函数不检查源区域中的任何终止空字符,始终精确复制指定数量的字节。
结果为数据的二进制副本。
注意:要从/向 Pointer 引用的内存复制,必须先对其解引用(或在参数中在指针名前加 Byval 关键字),否则 fb_memcopy 将尝试从/向指针变量本身所在的内存位置复制字节。
示例
vb
Type Person
Dim As ZString * 40 Name
Dim As Integer age
End Type
Dim As ZString Ptr mynameptr = @"Pierre de Fermat"
Dim As Person person1, person2
' using fb_memcopy to copy string
fb_memcopy(person1.Name, *mynameptr, Len(*mynameptr) + 1)
person1.age = 46
' using fb_memcopy to copy structure
fb_memcopy(person2, person1, SizeOf(Person))
Print person2.Name, person2.age
Sleep输出:
Pierre de Fermat 46版本
- 自 fbc 1.08.0 起
与 QB 的差异
- FreeBASIC 中的行为和用法为新增内容。
另请参阅
fb_memcopyclearfb_memmove
返回 目录