Const sucks

Bruce Adams tortoise_74 at yahoo.couknowthedrill.com
Mon Sep 10 17:06:51 PDT 2007


Sean Kelly Wrote:

> Walter Bright wrote:
> > Bruce Adams wrote:
> >>>> o  So, we still need a method to declare a constant that will not
> >>>>  consume memory. We'll co-opt the future macro syntax for that:
> >>>>
> >>>> macro x = 3; macro s = "hello";
> >> I'm not clear why this is even needed. Surely "static const" implies
> >> some level of don't consume any memory by virtue of meaning
> >> "available at compile time". If you need more than that, rather than
> >> trusting the compiler then I second "inline" rather than macro, but
> >> honestly I can't think of an example where this will give you a
> >> worthwhile performance gain (unlike an inline function).
> > 
> > windows.h in all its terrifying glory has 10,000 macro declarations. If 
> > each one occupied 4 bytes of static data, there's 40K of bloat in every 
> > exe.
> 
> That sounds about right.  When we converted const values to enum values 
> in the Tango Win32 headers, app size dropped by roughly 46k.  But there 
> were issues with some of those enum values having the wrong type (-1 set 
> to int instead of uint), which led to a few strange bugs.
> 
> 
> Sean

I seek enlightenmnet for at least two problems with that explanation.

windows.h is a C binding not a D binding.
I'm not clear how one translates to the other yet as I've avoided bi-lingual stuff so far. Presumably the D binding is created using htod.

I thought D followed the you only pay for what you use philosophy.
So if I import my windows.d module I will only pay the cost of the
variables I actually use. My friendly neighbourhoold compiler, being clever, mightl also make an effort to minimise the cost of those too.

While we're on the subject of windows. 40K means nothing. In an embedded system yes. Windows is bloated to the point where 40K in a user application means de nada. (I shudder at the 4Gb games that follow in its wake too). I have know idea where the windows mobile / CE / pocket PC api falls here.

Regards,

Bruce.



More information about the Digitalmars-d mailing list