Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

MemberPointersInPdbFiles

Michal Opler edited this page Aug 3, 2015 · 1 revision

Size of pointers in PDB files

In the type info stream of the PDB file pointers are represented with LF_POINTER records (as described in the CVInfo.h header file). The problem is that there is no specific size field. Instead each pointer has two attributes - pointer type and pointer mode. Pointer type basically determines whether the image is 32-bit or 64-bit and pointer mode specifies whether it's an ordinary pointer, a reference, a pointer to a data member or a pointer to a member function. Ordinary pointers in a 32-bit image are 4 bytes long and 8 bytes long in the case of a 64-bit image. However member data and member function pointers behave in a very different way.

Pointer to member functions and data members

For more details on why and how are member function pointers different see this article. The sizes of such pointers depend on the type of inheritance of the containing class and on the implementation of the compiler. Their PDB records have an extra field specifying whether they point to a class with single-, multiple-, virtual- inheritance, or unknown (i.e., forward declared)). We have experimentally determined the sizes of member data and function pointers in all of these cases as compiled by Visual Studio 12.0.31101.00.

Pointer type modes Single Multi Virtual Unknown
32-bit member data 4 4 8 12
32-bit member function 4 8 12 16
64-bit member data 4 4 8 12
64-bit member function 8 16 16 24

In order to determine these values we have used the following code.

#include <stdio.h>

class A {};
class B {};

class Single : public A {};
class Multi : public A, public B {};
class Virtual : virtual public A {};
class Unknown;

typedef int (Single::* SingleFunc)();
typedef int (Multi::* MultiFunc)();
typedef int (Virtual::* VirtualFunc)();
typedef int (Unknown::* UnknownFunc)();

typedef int* Single::* SingleData;
typedef int* Multi::* MultiData;
typedef int* Virtual::* VirtualData;
typedef int* Unknown::* UnknownData;

int main() {
  printf("single: data =  %u function = %u\n", 
         sizeof(SingleData), sizeof(SingleFunc));
  printf("multi: data =  %u function = %u\n",
         sizeof(MultiData), sizeof(MultiFunc));
  printf("virtual: data =  %u function = %u\n",
         sizeof(VirtualData), sizeof(VirtualFunc));
  printf("unknown: data =  %u function = %u\n",
         sizeof(UnknownData), sizeof(UnknownFunc));
}
Clone this wiki locally