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??? :( )
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??? :( )
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.
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.
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 ;)
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 ;)