Hi Stephan,

Thank you for your comments.

On 2011/05/18 4:11, Stephan Bergmann wrote:
> Binary UNO requires that its enums are of specific size, but that should be 
taken care of by the dummy max-value element in each enum.  Likewise for enums in 
the C/C++ URE ABI.
>
> Whether smaller enums have positive or negative runtime impact is hard to 
tell up front, I would say---and hard to measure, I would guess, as I assume the 
impact is negligible overall.  Similarly, I would assume the space savings to be 
negligible, too.

I used to think in the similar way as you did. But when I read some articles 
offered by Intel in order to find basic concepts of performance improvement, I 
was surprised and had learned.

Smaller data size improves the cache hit rate of the processor.
Smaller data size decreases the possibility of miss hit of virtual memory pages.

Programming application software in the level of C++ language, we might never 
consider underlying architecture.

When you jump in the world of what is DDR2-800 2GB memory module, what is 512-KB L2 
Cache, what is Translation Lookaside Buffer (TLB), what OS has to do when a "miss 
hit" occurs, ... you might be encouraged to explore the new world.

I have tried to find such articles, but cannot find them so far. This web page, 
however, might help you enjoy with the new concepts.
http://www.intel.com/products/processor/manuals/

Just an example from http://developer.intel.com/Assets/PDF/manual/248966.pdf
Example 3-44. Rearranging a Data Structure

struct unpacked { /* Fits in 20 bytes due to padding */
    int a;
    char b;
    int c;
    char d;
    int e;
};

struct packed { /* Fits in 16 bytes */
    int a;
    int c;
    int e;
    char b;
    char d;
}

http://hg.services.openoffice.org/OOO330/file/OOO330_m20/vcl/inc/vcl/impfont.hxx
class Impl_Font  /* Fits in 88 bytes */
{
  ... several enum ...
};

http://hg.services.openoffice.org/OOO330/file/8601acbe0e6c/vcl/inc/vcl/vclenum.hxx
enum FontItalic { ITALIC_NONE, ITALIC_OBLIQUE, ITALIC_NORMAL, ITALIC_DONTKNOW, 
FontItalic_FORCE_EQUAL_SIZE=SAL_MAX_ENUM };

could be rewrote in the following way:

#if defined( THIS_COMPILER ) && ( VERSION_OF_THE_COMPILER >= 0x9999 )
#define SAL_ATTRIBUTE_PACKED __attribute__ ((packed))
#else
#define SAL_ATTRIBUTE_PACKED
#endif

enum FontItalic { ITALIC_NONE, ITALIC_OBLIQUE, ITALIC_NORMAL, ITALIC_DONTKNOW, 
FontItalic_FORCE_EQUAL_SIZE=SAL_MAX_ENUM } SAL_ATTRIBUTE_PACKED;

The size of class Impl_Font would reduce to 50 bytes or so from 88 bytes.

How big benefits could we get when such structure or class instances are 
produced in large numbers?

Best regards,
Tora
--
-----------------------------------------------------------------
To unsubscribe send email to dev-unsubscr...@openoffice.org
For additional commands send email to sy...@openoffice.org
with Subject: help

Reply via email to