Click here to Skip to main content
14,974,167 members
Articles / DevOps
Posted 28 Jun 2016


6 bookmarked

Storage Sizes and Other Useful Properties: Windows, C++, and C Variable Types

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
28 Jun 2016CPOL5 min read
A reference chart that doubles as the engine behind a data structure mapper


About ten years ago, I created a simple chart that listed the basic properties, including storage requirements, of the most common basic (discrete) data types likely to be encountered in Windows programming. About a year and a half ago, I created a greatly expanded chart, along with charts focused on data types encountered in C and C++ programming.


In day to day programming, it is occasionally handy to be able to look up the basic properties of some type that you use infrequently, such as, for example, that a LANGID (Language ID) is a WORD, a 16 bit unsigned integer, while a LCID (Locale Identifier) is a DWORD, a 32 bit unsigned integer. Furthermore, having every primitive type you are likely to need organized into one chart, alphabetized by name (e. g., LANGID), with a named workbook scoped range defined over them makes child’s play of creating dead accurate structure definitions, complete with offsets, to document their organization and size, and as an invaluable debugging aid.

Using the Charts

I chose my section title intentionally, because there is no “code” in this article, only a Microsoft Excel workbook, Windows_and_C++_Data_Type_Tables.XLSX, and a companion Microsoft Word document, Windows_and_C++_Data_Type_Tables_Security.DOCX, which contains the passwords the protect the worksheets against accidental changes. Though you may never need them, you should have them, just in case.

Figure 1 shows the upper left corner of the Windows Data Types worksheet, while Figure 2 shows the part that I use most often. 

Upper Left Corner of Windows Data Types Worksheet

Figure 1 shows the upper left corner of the Windows Data Types worksheet, a comprehensive index of details about discrete (primitive) data types defined in the Windows SDK headers..

far right edge of the Windows Data Types worksheet

Figure 2 is the far right edge of the Windows Data Types worksheet shown in Figure 1, which is the part that I use most often.

Just above the detail columns shown in Figure 2 is a small chart that bears explanation. Above, I hinted that there is a named range defined over this table, and this chart is your quick guide to writing VLOOKUP formulas against it. Combined with the True/False values in columns AG and AH, such lookups populate columns AI, AJ, and AR based on the values set in input validated cells AI3 through AI5. Though the top two settings apply as well to the CRT, I learned, the hard way, that you must define _UNICODE to get a wide character call into the CRT library.

Pay particular attention to the three unprotected cells (the cells with a green background) shown at close range in Figure 3. These input validated cells let you specify which of the preprocessor symbols that affect memory sizes of objects are set for your build. These settings affect the values shown in columns 37 through 39, though mostly the latter two. For pointer types, column 39 shows the value in 38, otherwise, the value from column 37 appears; hence, it is identified as the value occupied by a structure member of that type.

CPP symbols that affect memory requirements

Figure 3 is a close-up of a three-celled area where you can indicate which of several preprocessor symbols are defined in your build; these determine the memory sizes shown in the chart below. This example shows the settings fora Win32 Unicode build.

Table 1 describes the key ranges defined over various parts of the workbook. Range Windows_Data_Types is especially useful because you can use it along with the numbers in row 5 of the worksheet to build a formula to look up the memory required to store a variable of a specific type or a pointer to such a variable. Column AB (number 36), labeled Prefix, contains my Hungarian notation prefixes; if you use different prefixes, you may input your own, and use this column to generate correctly prefixed Hungarian variable names.

Table 1 - Named Range Summary
Range Usage
Windows_Data_Types This named range returns all detail rows from worksheet Windows Data Types.
Windows_Variable_Name_Prefix Identify the column in sheet Windows Data Types that contains the prefix to assign to variable names of this type.
Windows_Variable_Type_IsPointer This column returns TRUE for any Windows type that is a pointer type.
Windows_Variable_Type_PointerSize For pointer types, indicate the size, in bytes, required to store the pointer for the specified architecture. For other types, this field is empty.
Windows_Variable_Type_Fundamental_CPP_Type All types report the equivalent fundamental C++ type, which, in turn, determines its storage requirement.
Windows_Variable_Type_StorageSize All types report through this column the storage requirements, based on the current preprocessor variable settings. For pointer types, this is the storage required for one entity of the type to which it points. To be consistent with the way the compiler interprets it, a void type or a pointer to void returns a storage size of zero.

Memory Layout of a OPENFILENAME_NT4A Structure

Figure 4 is worksheet OPENFILENAME_NT4A, a demonstration of how you can leverage the data in the Windows Data Types worksheet to map the memory requirements and layout of a data structure.

Figure 4 is an example of how you can map the layout of a structure in memory; please feel free to use this as a starting point for your own worksheets, since you may as well take full advantage of the work I already put into it. I chose the OPENFILENAME_NT4A structure, defined in commdlg.h, because it includes a variety of items, and is sufficiently big that you probably don’t want to work out an offset by counting members. This structure contains one member, lpfnHook, that isn’t a primitive type, and a couple of pointer types. However, cell D24 shows the typedef, also in commdlg.h, from which I deduced that it is a UINT_PTR, which is one.

The Hungarian variable names worksheet is left for the enterprising reader, but there is more than enough information in this article and the workbook that you should be able to do so quickly and easily.

You are on your own to explore the other worksheets, and I shall be happy to entertain questions in the discussion threads that attach themselves to the article.

Points of Interest

The workbook included with this article sports two new columns that further simplify its use in constructing memory maps of data structures, along with the sample structure worksheet. I plan to overwrite my original with this improved version for use going forward.


Wednesday, 28 June 2016, submitted for publication.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

David A. Gray
Software Developer (Senior)
United States United States
I deliver robust, clean, adaptable, future-ready applications that are properly documented for users and maintainers. I have deep knowledge in multiple technologies and broad familiarity with computer and software technologies of yesterday, today, and tomorrow.

While it isn't perceived as sexy, my focus has always been the back end of the application stack, where data arrives from a multitude of sources, and is converted into reports that express my interpretation of The Fundamental Principle of Tabular Reporting, and are the most visible aspect of the system to senior executives who approve the projects and sign the checks.

While I can design a front end, I prefer to work at the back end, getting data into the system from outside sources, such as other computers, electronic sensors, and so forth, and getting it out of the system, as reports to IDENTIFY and SOLVE problems.

When presented with a problem, I focus on identifying and solving the root problem for the long term.

Specialties: Design: Relational data base design, focusing on reporting; organization and presentation of large document collections such as MSDS libraries

Development: Powerful, imaginative utility programs and scripts for automated systems management and maintenance

Industries: Property management, Employee Health and Safety, Services

Languages: C#, C++, C, Python, VBA, Visual Basic, Perl, WinBatch, SQL, XML, HTML, Javascript

Outside Interests: Great music (mostly, but by no means limited to, classical), viewing and photographing sunsets and clouds, traveling by car on small country roads, attending museum exhibits (fine art, history, science, technology), long walks, especially where there is little or no motor traffic, reading, especially nonfiction and thoughtfully written, thought provoking science fiction

Comments and Discussions

Generalvery good info Pin
Southmountain12-Aug-17 9:11
MemberSouthmountain12-Aug-17 9:11 
PraiseThanks, appreciate the work you put into this Pin
KBZX500030-Jun-16 1:52
MemberKBZX500030-Jun-16 1:52 
GeneralRe: Thanks, appreciate the work you put into this Pin
David A. Gray30-Jun-16 3:41
MemberDavid A. Gray30-Jun-16 3:41 
BugUnreadable images Pin
Philippe Mori29-Jun-16 4:05
MemberPhilippe Mori29-Jun-16 4:05 
GeneralRe: Unreadable images Pin
David A. Gray29-Jun-16 10:21
MemberDavid A. Gray29-Jun-16 10:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.