[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: ByteBuffer.allocateDirect ridiculously slow

clebert.suconic@jboss.com do-not-reply at jboss.com
Tue Mar 3 08:17:06 EST 2009


"timfox" wrote : It's a well known fact that direct bytebuffer allocation is much slower than non direct byte buffers.
  | 
  | If you think about it when you allocate a non direct byte buffer then it basically just needs to dereference a pointer to some memory on the Java heap, which is very quick. But for a direct buffer, it has to malloc real memory from the OS, and do a bunch of other house keeping.
  | 
  | So yes, if you're using direct byte buffers it pays to re-use them.
  | 
  | You should speak to Trustin about this. I believe Netty uses non direct buffers for exactly this reason.


I need a direct buffer on AIO, because of memory alignments and JNI invocations.

But there shouldn' t be a reason for that. If I called malloc/posix_mem_align (which is the same as malloc, but aligned) and created the direct myself using the memory position, and a JNI method,  it would be way much faster (100x as my test showed).

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4214497#4214497

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4214497



More information about the jboss-dev-forums mailing list