基指针 (C)Based Pointers (C)

Microsoft 专用Microsoft Specific

__based(C++ 参考)__based (C++ Reference)

对于 Microsoft 32 位和 64 位 C 编译器,基指针是相对于 32 位或 64 位指针基的 32 位或 64 位偏移量。For the Microsoft 32-bit and 64-bit C compilers, a based pointer is a 32-bit or 64-bit offset from a 32-bit or 64-bit pointer base. 基寻址对于控制分配对象的部分很有用,这可减少可执行文件的大小并加快执行速度。Based addressing is useful for exercising control over sections where objects are allocated, thereby decreasing the size of the executable file and increasing execution speed. 通常,用于指定基指针的形式为In general, the form for specifying a based pointer is


type  
__based(  
base  
)  
declarator  

基寻址的“based on pointer”变体支持作为基的指针的规范。The "based on pointer" variant of based addressing enables specification of a pointer as a base. 该基指针是内存部分的偏移量,它从所基于的指针开始。The based pointer, then, is an offset into the memory section starting at the beginning of the pointer on which it is based. 基于指针地址的指针是 32 位和 64 位编译中唯一有效的 __based 关键字形式。Pointers based on pointer addresses are the only form of the __based keyword valid in 32-bit and 64-bit compilations. 在这些编译中,它们是来自 32 位或 64 位基的 32 位或 64 位置换。In such compilations, they are 32-bit or 64-bit displacements from a 32-bit or 64-bit base.

基于指针的指针的用途之一是用于包含指针的永久标识符。One use for pointers based on pointers is for persistent identifiers that contain pointers. 可将包含基于指针的指针的链接列表保存到磁盘,然后重新加载到内存中的另一个位置,并且指针保持有效。A linked list that consists of pointers based on a pointer can be saved to disk, then reloaded to another place in memory, with the pointers remaining valid.

以下示例演示基于指针的指针。The following example shows a pointer based on a pointer.

void *vpBuffer;  

struct llist_t  
{  
    void __based( vpBuffer ) *vpData;  
    struct llist_t __based( vpBuffer ) *llNext;  
};  

将指针 vpBuffer 分配给程序中后面某个时间点分配的内存地址。The pointer vpBuffer is assigned the address of memory allocated at some later point in the program. 相对于 vpBuffer 的值重新定位链接的列表。The linked list is relocated relative to the value of vpBuffer.

结束 Microsoft 专用END Microsoft Specific

另请参阅See Also

声明符和变量声明Declarators and Variable Declarations