You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andrea Vacondio <an...@gmail.com> on 2015/02/13 12:48:22 UTC

Mutable COSInteger

Hi,
I was looking at the COSInteger and I have a couple of questions.
I noticed that it caches instances between in -100 and 265.
My first question is why those limits and not cache everything... perhaps
with Soft or Weak values? I made a very rough test using a Map to cache all
the COSInteger and I loaded the 32MB pdf_reference_1-7.pdf, it saved a
couple of MB of memory and about 130k COSInteger instances, not much but
still... Is there any reason I'm missing for those limits?
Second question. They are cached and they are mutable so this:
    {
        COSInteger cosint = COSInteger.get(10);
        cosint.setValue(50);
        //lets move to a totally unrelated part of my software
        System.out.println(COSInteger.get(10));
    }

prints COS{50} so basically I ask for a 10 and get a 50, isn't it weird
(and error prone)? ... or the way around, I call cosint.setValue(50) at
some point in the software and that makes it a 50 everywhere I used
COSInteger.get(10).
That's of course also true for the other mutable attributes setDirect and
setNeedToBeUpdate.
Thoughts?

Re: Mutable COSInteger

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.02.2015 um 12:48 schrieb Andrea Vacondio:
> Hi,
> I was looking at the COSInteger and I have a couple of questions.
> I noticed that it caches instances between in -100 and 265.
> My first question is why those limits and not cache everything... perhaps
> with Soft or Weak values? I made a very rough test using a Map to cache all
> the COSInteger and I loaded the 32MB pdf_reference_1-7.pdf, it saved a
> couple of MB of memory and about 130k COSInteger instances, not much but
> still... Is there any reason I'm missing for those limits?
> Second question. They are cached and they are mutable so this:
>      {
>          COSInteger cosint = COSInteger.get(10);
>          cosint.setValue(50);
>          //lets move to a totally unrelated part of my software
>          System.out.println(COSInteger.get(10));
>      }
>
> prints COS{50} so basically I ask for a 10 and get a 50, isn't it weird
> (and error prone)? ... or the way around, I call cosint.setValue(50) at
> some point in the software and that makes it a 50 everywhere I used
> COSInteger.get(10).
> That's of course also true for the other mutable attributes setDirect and
> setNeedToBeUpdate.
> Thoughts?
that you're fearless and like to travel to the dark alleys of PDFBox?

I've opened
https://issues.apache.org/jira/browse/PDFBOX-2685

About what to do? First thought: remove setValue(). I thought that a red 
light would go on in the IDE, but no. However that doesn't solve the 
problem about setDirect and setNeedToBeUpdate.

Tilman

PS: These kind of discussions better be in the dev list.

>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org