Moving structs containing strings ...

Bob W nospam at
Mon Apr 24 14:46:35 PDT 2006

"Frits van Bommel" <fvbommel at> wrote in message 
news:e2iqkp$2fvl$1 at
> How about defining the struct like this:
> struct Sc { uint val;  char[3] idz;  char[] id() { return idz[0..3]; } }
> This turns 'id' into a property instead of a field. This might be slightly 
> slower*, but has several advantages:

No idea what slightly slower means to you, but I can
guarantee you that with indirect string access you
won't even get to 50% of the original speed.

> - It will always return the current string without needing manual updates.

I need direct access to the strings, due to performance
reasons. Therefore I do not mind the updates whenerver
they are required.

> - It doesn't allocate.

This would be unacceptable anyway.

> - It removes the need to initialize 'id' separately.

You are referring to the sample which has those
convenient constant length strings. My application
does not work this way, however. I'd have to
have some basic initialisation first in order to
get quicker access later.

> - Added bonus: Sc.sizeof is halved. (goes from 16 bytes to 8 bytes)

I guess most of us have 1 or 2GB installed these days, true?

Don't get me wrong. Your idea would be definitely
worthwhile considering for other applications. But it
just does not fit my current requirements.

More information about the Digitalmars-d-bugs mailing list