Intel® Software Network Knowledge Base Wiki


Constructing Nav Tree
One Moment...

(refresh menu)



 
Welcome, Guest | Quick Login | Register

Develop for Core processor


Replace a Set of Pointers With a Base Pointer to Reduce Data Bloat

Version 2, Changed by KYLE LEWIS on 1/3/2008
Created by: KYLEX.S.LEWIS@INTEL.COM

Challenge

Reduce data bloat due to the use of many pointers. Pointers in the Itanium® architecture are twice the size of pointers in 32-bit Intel® architecture, which may effectively double the size of data structures that are largely composed of pointers.

The following code defines a structure composed entirely of pointers:

<br /> 
struct f {<br /><br /> 
f *Pnextf;<br /><br /> 
g *Psibling;<br /><br /> 
h *Pparent;<br /><br /> 
}; 

Solution

Redesign data structures that contain many pointers to use 32-bit offsets from a base pointer instead of using full 64-bit pointers. To do this, you can use a Windows*-compatible compiler and apply the __based attribute to pointers. You might also be able to convert pointers into smaller-sized array indexes. Modifications like these must be accompanied by changes to your application source code. Instead of a simple C de-reference (-&gt;), your code must calculate an address, or you must change it to use array subscripting ([]). Careful use of macros or C++ overloaded operators can preserve easy readability of your source code.

The code sample below represents a revision of the code given in the "Challenge" section. It defines a structure (struct f) composed of smaller data fields that will be used to point to elements of the structure:

01 Typedef HALF_PTR int;<br /> 
02 void *heap;<br /> 
03 struct f {<br />
04 int nextf_idx;<br /> 
05 HALF_PTR siblingOffset;<br /> 
06 h __based(heap) *_ptr32 Pparent<br /> 
07 };<br />
08 ...<br /> 
09 f_array[nextf_idx]<br />
10 (g*)((uintptr_t)this+this.siblingOffset<br />
11 this->Pparent 

Line 2 defines a pointer to heap that allocates objects within a 32-bit address sub-range. Line 6 uses a Microsoft*- specific extension (__based) to create an offset within the heap sufficient to reach all allocated members. Line 5 declares a data type that will be used as an offset to a pointer. Lines 9 through 11 declare that the data item is pointed to by a pointer-plus-offset calculation instead of direct 64-bit addressing. Line 9 defines a simple array index. Line 10 is a base + displacement calculation that needs to be inserted into your code. Line 11 illustrates how the complicated declaration in the structure (line 6) allows simple, traditional, straightforward use of the structure fields in user source. Revising your code to use this construction will allow you to use these smaller "pointer-like" fields.

Additional issues related to managing data size and avoiding data bloat during migration to 64-bit Intel architecture are addressed in separate items:

How to Use Appropriate Data Types to Manage 64-bit Data Size

How to Manage Structure Padding to Avoid Data Bloat

Source

Preparing Code for the IA-64 Architecture (Code Clean)

 



Served
23 Knowledge Bases
604 Pages
Search
Powering Up Search...


Vote on this Page

Tags For This Page
Loading Tags..

Tag This



Additional legal information