gpt4 book ai didi

c - mmap ed 区域是 "single object"吗?我可以比较其中的指针吗?

转载 作者:行者123 更新时间:2023-12-02 00:54:46 25 4
gpt4 key购买 nike

我正在使用 mmap 进行 malloc 实现作为学校练习。

我想通过使用元数据的地址来计算空闲列表中我的内存块的大小。

但我不确定这个解决方案是否会在 C 标准中得到明确定义,我没有找到关于 mmap 分配区域是否被视为 C 的那部分含义中的“对象”的引用标准:

§6.5.8.5(引自 that answer 到一个有点相关的问题):

When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to. If two pointers to object or incomplete types both point to the same object, or both point one past the last element of the same array object, they compare equal. If the objects pointed to are members of the same aggregate object, pointers to structure members declared later compare greater than pointers to members declared earlier in the structure, and pointers to array elements with larger subscript values compare greater than pointers to elements of the same array with lower subscript values. All pointers to members of the same union object compare equal. If the expression P points to an element of an array object and the expression Q points to the last element of the same array object, the pointer expression Q+1 compares greater than P. In all other cases, the behavior is undefined.

换句话说,我可以将 mmap 区域视为标准中的字节数组(或 char)吗?

最佳答案

是的,你可以合理地这样做,作为一个最初没有有效类型的对象 - 否则 mmap 系统调用将完全无用 并且可以期望针对 POSIX 系统的 C 编译器不应该使 mmap 无用......

关于c - mmap ed 区域是 "single object"吗?我可以比较其中的指针吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55120055/

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