Re: Internal Representation of Strings

"Bartc" <bartc@freeuk.com>
Wed, 18 Feb 2009 11:49:45 GMT

          From comp.compilers

Related articles
[8 earlier articles]
Re: Internal Representation of Strings cr88192@hotmail.com (cr88192) (2009-02-16)
Re: Internal Representation of Strings tony@my.net (Tony) (2009-02-15)
Re: Internal Representation of Strings DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-02-16)
Re: Internal Representation of Strings bartc@freeuk.com (Bartc) (2009-02-16)
Re: Internal Representation of Strings wclodius@lost-alamos.pet (2009-02-16)
Re: Internal Representation of Strings ArarghMail902@Arargh.com (2009-02-17)
Re: Internal Representation of Strings bartc@freeuk.com (Bartc) (2009-02-18)
Re: Internal Representation of Strings tony@my.net (Tony) (2009-02-18)
Re: Internal Representation of Strings tony@my.net (Tony) (2009-02-18)
Re: Internal Representation of Strings cr88192@hotmail.com (cr88192) (2009-02-19)
Re: Internal Representation of Strings cr88192@hotmail.com (cr88192) (2009-02-21)
Re: Internal Representation of Strings tony@my.net (Tony) (2009-02-21)
Re: Internal Representation of Strings idbaxter@semdesigns.com (Ira Baxter) (2009-02-21)
[19 later articles]
| List of all articles for this month |
From: "Bartc" <bartc@freeuk.com>
Newsgroups: comp.compilers
Date: Wed, 18 Feb 2009 11:49:45 GMT
Organization: Compilers Central
References: 09-02-051 09-02-068 09-02-078 09-02-084
Keywords: storage, comment
Posted-Date: 18 Feb 2009 17:08:54 EST

"Bartc" <bartc@freeuk.com> wrote in message news:09-02-084@comp.compilers...


> I'm thinking of the following representation for short strings 2 to 256
> characters, designed for use as array and record elements.


> So I store the length using the final two bytes as follows, for a string
> with 8 bytes:
>
> 0,0 Length is 0
> 0,N Length is N (up to 6)
> X,0 Length is 7
> X,Y Length is 8


> [This sounds awfully complicated for an in-memory design. Why not just
> use a four byte length and code more compactly if needed on I/O. -John]


I use a 4-byte length in other places, but where a string is short, it
does seem attractive to use all available bytes and not waste one for
a length or terminator (and if I wanted up to 8 useable characters,
that would mean using an odd 9-byte field).


Extracting the length is perhaps 3 x86 instructions for most strings,
maximum 5. Compared with one instruction to pick up the length from a
regular string. (Of course I haven't actually tried it yet..)


--
Bartc
[In a world where laptops have a gigabyte of RAM, what's the point in trying to save
a few bytes with structures in memory? -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.