If you don't specify a starting buffer size you get space for 16
characters. Then each time it exceeds the allocated amount it allocates
twice the space and copies the characters appended so far, which is time
consuming and memory intensive, perhaps many times (the spent buffers
are reclaimed by garbage collection eventually, but till then they're
gobbling memory). Since the average html page exceeds 16 characters
it's speedier to specify a larger buffer to start. Maybe 4096 is a bit
agressive, but I bet it covers a majority of the pages out there and a
study would need to be done to find out a more optimal size. This is
only allocated once per StringBean so it's not a big deal either way.
Mr LING MA wrote:
>Hi:
>will the StringBean program use less memory if
>initialize StringBuffer as 0 bytes ? why 4096?
>
>Ling Ma
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Search - Faster. Easier. Bingo.
>http://search.yahoo.com
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Htmlparser-developer mailing list
>Htm...@li...
>https://lists.sourceforge.net/lists/listinfo/htmlparser-developer
>
>
>
|