On 01/02/12 09:36, Olivier Mascia wrote:
> I'm reading the Firebird Internals pdf documentation and feel puzzled about 
> the encoding of two repeating bytes.
>
> "You may have noticed that the two consecutive characters 'DD' did not get 
> compressed. Compression only takes place when there are three or more 
> identical characters."
>
> Indeed the pdf shows example data as:
>
> 01 fe fd 00 03 20 00 41 fc 61 01 42 f7 62 01 43 f2 63  { 02 44 44 }  bc 00
>
> and the sequence "DD" which I placed between { } looks encoded as "those next 
> 2 bytes as is".
>
> Why isn't this encoded as {ff 44} which is not shorter than the initial data, 
> but at least is not larger.
>
> I'm sure I'm facing some blatant evidence here, but it did not yet strike on 
> me.
> Help! What did I misunderstand?
Nothing at all!

There is nothing here to misunderstand. The I assume that original 
developers of "Jim's Relational database" aka Interbase aka Firebird 
probably took the decision that encoding and decoding two identical 
bytes was easier to use 02 xx xx rather than fe xx - maybe a trade off 
between performance and space usage.

Given the time that JRD was originally developed, CPUs weren't as quick 
as they are nowadays? My first ever PC was an 80386 DX running at 10 Mhz 
with Turbo boost to 40 MHz.

Basically, it's most likely just a design decision.

If you look closer you'll see that 01 xx is two bytes rather than just 
the one copied to the output - so there are other "foibles" in there 
with the RLE. But how else would you define copying byte(s) unchanged to 
the output?

I wrote, many years ago, in MC68000 assembler an RLE encoder decoder 
which simply scanned the input looking for consecutive bytes. I output 
an ESC character (ASCII 27, 0x1b) as a marker byte, then a count byte, 
then the repeating byte. If a byte in the file was itself 0x1b then I 
doubled it up as 0x1b 0x1b.

So, all RLE systems have their advantages and their drawbacks and in the 
end, all are a trade off.

HTH


Cheers,
Norm.

PS. One day I'll finish decoding the internals and finish the manual! 
Thanks for reading so far.

-- 
Norman Dunbar
Dunbar IT Consultants Ltd

Registered address:
Thorpe House
61 Richardshaw Lane
Pudsey
West Yorkshire
United Kingdom
LS28 7EL

Company Number: 05132767

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to