Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

buffer sizes

15 views
Skip to first unread message

bob

unread,
Oct 9, 2012, 10:50:00 AM10/9/12
to
I noticed that many buffer sizes tend to be powers of two.

Does this really matter that much?

Is a buffer that is 16384 bytes really any better than one that is 16000 bytes?

Ant

unread,
Oct 9, 2012, 12:39:12 PM10/9/12
to
"bob" wrote:

> I noticed that many buffer sizes tend to be powers of two.
> Does this really matter that much?

Obviously it depends on the application, operating system and level
(language, API) at which you are programming. If an algorithm requires
256 bytes of storage then that's what you need. Operating systems tend
to map memory page sizes as powers of 2 (e.g. 4096 bytes) so if you're
working at a low level or within the kernel it may be that multiples
of the page size only are allowed in allocation routines. At a higher
level it won't matter as the memory management will be done for you.

> Is a buffer that is 16384 bytes really any better than one that is 16000 bytes?

It could actually waste memory in a normal application. If you only
need 16000 bytes then that's what you should allocate. If you try to
second-guess what the OS might really allocate internally, given the
page size, you are likely to use more than 16384 (if that's what you
specify) because another page gets allocated for overhead (headers,
etc.) added by the heap allocation routines you're using.


0 new messages