Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL: Bufferutil.createbytebuffer() vs. ByteBuffer.allocatedirect()  (Read 1888 times)
0 Members and 1 Guest are viewing this topic.
Offline deepthought
« Posted 2012-12-01 17:15:49 »

Is there a difference? are there any reasons i should use one over the other?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-12-01 17:19:24 »

The difference is described in the javadocs.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gouessej
« Reply #2 - Posted 2012-12-01 17:50:03 »

Riven is right, BufferUtils.createByteBuffer(int) does the same thing than ByteBuffer.allocateDirect() except that it sets its byte order to the native one of the platform. It probably does :
1  
ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deepthought
« Reply #3 - Posted 2012-12-01 18:06:12 »

so it doesn't return a bytebuffer that doesn't leak?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2012-12-01 18:07:35 »

It does return a bytebuffer that doesn't leak, simply because bytebuffers never leak. That'd be messy.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gouessej
« Reply #5 - Posted 2012-12-01 18:32:53 »

so it doesn't return a bytebuffer that doesn't leak?
What do you mean? An undirected NIO buffer is allocated on the Java heap but a direct NIO buffer is allocated on the native heap. The former doesn't need any intervention of the programmer to be garbage collected whereas the latter may require some help, for example when you still have a lot of memory available in the Java heap but not in the native heap.

Offline deepthought
« Reply #6 - Posted 2012-12-02 04:06:54 »

so it doesn't return a bytebuffer that doesn't leak?
What do you mean? An undirected NIO buffer is allocated on the Java heap but a direct NIO buffer is allocated on the native heap. The former doesn't need any intervention of the programmer to be garbage collected whereas the latter may require some help, for example when you still have a lot of memory available in the Java heap but not in the native heap.

I was wondering if one returned by bufferutils gets helped along. How would I go about making one get rid of it's memory?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2012-12-02 04:09:55 »

Exactly the same as how you ensure a byte[n] gets eventually cleaned up.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gouessej
« Reply #8 - Posted 2012-12-04 14:19:44 »

so it doesn't return a bytebuffer that doesn't leak?
What do you mean? An undirected NIO buffer is allocated on the Java heap but a direct NIO buffer is allocated on the native heap. The former doesn't need any intervention of the programmer to be garbage collected whereas the latter may require some help, for example when you still have a lot of memory available in the Java heap but not in the native heap.

I was wondering if one returned by bufferutils gets helped along. How would I go about making one get rid of it's memory?
Follow Riven's suggestion and if the JVM needs a kick in its ass, get the cleaner of your direct NIO buffer and call it but you must be absolutely sure that the VBO using it has been destroyed before.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2012-12-04 15:20:36 »

User beware.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (5 views)
2014-07-24 01:59:36

Riven (7 views)
2014-07-23 21:16:32

Riven (8 views)
2014-07-23 21:07:15

Riven (9 views)
2014-07-23 20:56:16

ctomni231 (41 views)
2014-07-18 06:55:21

Zero Volt (37 views)
2014-07-17 23:47:54

danieldean (31 views)
2014-07-17 23:41:23

MustardPeter (33 views)
2014-07-16 23:30:00

Cero (48 views)
2014-07-16 00:42:17

Riven (49 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!