gpt4 book ai didi

objective-c - Mac OS X 相当于 SecureZeroMemory/RtlSecureZeroMemory?

转载 作者:太空狗 更新时间:2023-10-30 03:25:51 32 4
gpt4 key购买 nike

Mac OS X 是否有等同于 RtlSecureZeroMemory 的版本?/SecureZeroMemory ,一个将内存块清零的函数,但调用不会被编译器优化掉?

最佳答案

编写自己的函数:

void secure_zero(void *s, size_t n)
{
volatile char *p = s;

while (n--) *p++ = 0;
}

编辑:评论中的问题,为什么不用memset?如果不再访问数组对象,编译器可以优化 memset 函数调用。

请注意,C11 添加了(可选)函数 memset_s 并且标准保证函数调用不会被优化掉:

(C11, K.3.7.4.1p4) "[...] Unlike memset, any call to the memset_s function shall be evaluated strictly according to the rules of the abstract machine as described in (5.1.2.3). That is, any call to the memset_s function shall assume that the memory indicated by s and n may be accessible in the future and thus must contain the values indicated by c."

关于objective-c - Mac OS X 相当于 SecureZeroMemory/RtlSecureZeroMemory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13299420/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com