I'm writting a PCX encoder.

It gets data from memory and encodes to memory.

But, output memory size is unknown until encoding is finished.

How can I solve this problem...?
(The only way is to allocate a big and sufficient memory??? :( )
Posted on 2002-08-12 03:31:34 by nyam
Do 2 passes. ;)

First pass: Run encoding routine, but instead of outputting any data, keep an internal counter of # of bytes used.

Second pass: Allocate # of bytes from first pass and encode.
Posted on 2002-08-12 03:40:38 by iblis
My thoughts:

Allocate a start buffer, lets say 4096 byte.

@@:

Start writing into that buffer and count the byes you wrote in your routine.
If you get to <=10 remaining bytes, allocate another 4k chunk.

jmp @B ;)
Posted on 2002-08-12 03:42:10 by bazik