Re: what happens to buffer ?
- From: Gordon Beaton <n.o.t@xxxxxxxxx>
- Date: 30 Mar 2006 12:45:13 +0100
On 30 Mar 2006 02:30:31 -0800, gk wrote:
what should be the size of buffer ?
is byte[] buffer = new byte[512]; ENOUGH ?
suppose, at some point of time huge number of bytes (say 1000 bytes)
stormed .
Then what will happen ? the buffer cant accept more than 512 bytes
.....will the additional bytes 1000-512 = 488 will still be in the
stream ? or they will be lost ?
the reason is, some people use
byte[] buffer = new byte[256];
byte[] buffer = new byte[512];
byte[] buffer = new byte[1024];
which one is good ?
or anything is ok . does it matter really ? does the coder
responsible for choosing the size of the byte ?
Each time you call read(), the new bytes are written at the start of
the buffer unless you tell read() to do otherwise. If there were
already some data in the buffer from a previous read, it will be
overwritten with the new data.
Also, read() will never read more than the number of characters you
request, or the length of the buffer if you don't specify. Note that
read() can and often will return *fewer* characters than you request,
so you need to check the return value.
Any bytes you don't read will wait nicely in the stream until you
choose to read them.
So you can decide to read as much or as little as you want each time,
and can choose an apropriate buffer size. Normally it's more efficient
to read a lot of data each time and in powers of two, but depending on
your application you may want to read less.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.
- Follow-Ups:
- Re: what happens to buffer ?
- From: Patricia Shanahan
- Re: what happens to buffer ?
- References:
- what happens to buffer ?
- From: gk
- Re: what happens to buffer ?
- From: Thomas Schodt
- Re: what happens to buffer ?
- From: gk
- Re: what happens to buffer ?
- From: Chris Uppal
- Re: what happens to buffer ?
- From: gk
- what happens to buffer ?
- Prev by Date: Re: Difference between String variable and String Class definition
- Next by Date: Re: Splitting strings
- Previous by thread: Re: what happens to buffer ?
- Next by thread: Re: what happens to buffer ?
- Index(es):
Relevant Pages
|