Re: [Newbie Question] Magic Number's dangerous?
- From: Chris Smith <cdsmith@xxxxxxx>
- Date: Sat, 26 Nov 2005 09:36:16 -0700
> On 2005-11-25, Thomas Hawtin penned:
> > byte[] buff = new byte[8192];
> >
> > byte[] buff = new byte[SOME_BUFFER_LENGTH];
Monique Y. Mudama <spam@xxxxxxxxxxxxxxxx> wrote:
>
> Seems like you're dodging the issue here by giving a poor example.
> The fact is that you must have chosen 8192 for a reason, and that
> reason can be documented with a well-chosen variable name.
Nah, I don't see that that's necessarily the case. When choosing buffer
sizes, it's generally a matter of taking a guess. Usually, the guess is
a power of two, because it works better with MMU/paging architectures
where memory is typically allocated in pages of a power of two in size.
Tuning can be done later if it becomes a performance problem of some
kind. If there's some other kind of ultimate method of calculating
ideal buffer sizes, then most of us haven't yet been informed.
I typically choose buffers of size 32768 unless I have some reason not
to. Obviously, Thomas Hawtin commonly uses 8192. Why? No particular
reason. If it starts mattering in a measurable way, then I'm sure
they'll get tuned, and then a comment will be added explaining the
method used to choose the buffer size and the observed consequences of
making it too large/small.
In any case, even if the buffer size is carefully tuned, I very much
doubt that you could explain the method or logic behind the choice in a
reasonable identifier name.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.
- References:
- [Newbie Question] Magic Number's dangerous?
- From: seungwoo . yu
- Re: [Newbie Question] Magic Number's dangerous?
- From: Thomas Hawtin
- Re: [Newbie Question] Magic Number's dangerous?
- From: Monique Y. Mudama
- [Newbie Question] Magic Number's dangerous?
- Prev by Date: Re: Oracle ADF
- Next by Date: Re: Stream Corrupted while connection
- Previous by thread: Re: [Newbie Question] Magic Number's dangerous?
- Next by thread: Re: [Newbie Question] Magic Number's dangerous?
- Index(es):
Relevant Pages
|