Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Direct ByteBuffer advantage?

Thread view: 
Remon van Vliet - 19 May 2005 15:08 GMT
Hello,

I was wondering, is there a big advantage over using small direct
bytebuffers for the actual SocketChannel.read() and write() methods instead
of heap-allocated bytebuffers.

I'm working on a server and having a small direct buffer for the actual IO
is a bit of a pain. So, what are the advantages and does anyone have
practical experiences with the difference between the two? I understand that
directly allocated buffers can potentially be mapped to native buffers and
whatnot, but still...it's a bit of a hassle.

Remon
John C. Bollinger - 19 May 2005 19:31 GMT
> Hello,
>
[quoted text clipped - 7 lines]
> directly allocated buffers can potentially be mapped to native buffers and
> whatnot, but still...it's a bit of a hassle.

If the pain is already suffered then I don't see why you want to change
the code.  On the other hand, if you are just anticipating the pain and
hassle then I would recommend instead writing straightforward code and
worrying only if it ends up not meeting your performance requirements.

Out of curiosity, however, what makes direct ByteBuffers so much more
trouble than others?

Signature

John Bollinger
jobollin@indiana.edu

Remon van Vliet - 01 Jun 2005 13:52 GMT
Well, the thing is, direct buffers do not have a backing array
(byte[]). So, when i use small direct buffers for reads and writes, at
some point i have to put the contents of the direct buffer into a
larger bytebuffer (one that represents the entire packet i am trying to
send). The catch is that i may need to put the first half of the direct
buffer in one larger buffer (for example, if it's the end few bytes of
the previous packet) and put the rest in a new buffer. And there is
no(?) way to put a specific part (offset + length) of bytebuffer A in
bytebuffer B.

If there is an incorrect assumption in my reasoning let me know ;)

> > Hello,
> >
[quoted text clipped - 15 lines]
> Out of curiosity, however, what makes direct ByteBuffers so much more
> trouble than others?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.