Hello,
I have a multi-threaded application that parses in memory PDFs. At first I used 
buffer->PdfMemDocument for reading and OutputDevice(ostream)-> buffer to write 
to memory but i keep getting a race condition on the stream (even tough I have 
separate mem documents, something with the imbue thingy). So I've written a 
class that inherits PdfMemDocument and includes a function that writes to a 
buffer, same way the normal write works, except at the end I call 
writer.writetobuffer(..,..). The problem appears when I parse and write a large 
file (~19M). When it writes it to the buffer i get out-of-memory error. I 
traced it back to the output device and it seems the position has reached the 
end of the buffer in outputdevice. Is there any other initialization i have to 
do to get write-to-buffer to work?
My code looks like this.

size_t write(char ** pp)
{
PdfWriter wr(&(this->GetObjects()),this->GetTrailer());
wr.SetPdfVersion(this->GetPdfVersion());
wr.SetWriteMode(ePdfWriteMode_Compact);
size_t wl;
if (this->GetEncrypted())
wr.SetEncrypted(*(this->GetEncrypt()));
try{
wr.WriteToBuffer(pp,&wl);
}
catch(PDFError &e){
e.PrintErrorMsg();
}
} 


PoDoFo is out of memory
CallStack:
#0 ......PdfWriter.cpp:163
#1.......PdfOutputDevice.cpp:209

podofo version 0.9.1
<<Ignore compilation/syntax errors this is not copy-paste>>

One question why  is write-to-buffer writing twice? once in local variable 
device, and after that in buffer output device memDevice(from where i get my 
buffer). Is it writing just to get the size of the buffer? Isn't it a bit 
redundant? Or am I getting it wrong?

The program ran fine when I used the ostream except for the race condition 
(locking the write gave me heavy performance penalties). The program is very 
time sensitive. 

Thank you,
Lucian.
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to