Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HALF_PTR Windows data type

The VS documentation states

Half the size of a pointer. Use within a structure that contains a pointer and two small fields.

Windows Data Types

What, exactly, is this type and how is it used, if ever?

like image 261
Kristian D'Amato Avatar asked Jul 01 '26 22:07

Kristian D'Amato


2 Answers

Note: Anonymous structs are not standard, but MSVC takes them:

union
{
    int * aPointer
    struct
    {
        HALF_PTR lowerBits;
        HALF_PTR upperBits;
    };
} myvar; //You can be assured this union is sizeof(int *)

If you're thinking they're not too terribly useful, you would be right.

like image 73
Billy ONeal Avatar answered Jul 04 '26 12:07

Billy ONeal


I found this article on Intel's site, and it they suggest using it in a context where you have a class with many pointer members, along with a 32-bit offset to get the actual address, to cut down on data bloat of a class. The article specifically talks about the Itanium platform because it uses 64-bit pointers instead of 32-bit, but I assume the problem/solution to the problem would be the same on any system using 64-bit pointers.

So in short, it seems to suggest that it can be used if you, for example, wish to reduce the memory footprint of a class?

like image 41
Jacob Avatar answered Jul 04 '26 13:07

Jacob