Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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  
  float[] vs FloatBuffer  (Read 2977 times)
0 Members and 1 Guest are viewing this topic.
Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Posted 2003-01-28 07:34:18 »

I've notice that using a FloatBuffer is faster than using an array of float. Is this true ? could someone explains me why ?

++
Chman
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #1 - Posted 2003-01-28 07:40:45 »

Faster for what?
If it's passing through JNI, then it's because that's what direct buffers are all about...

Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #2 - Posted 2003-01-28 08:28:53 »

I mean that calling a buffer member (for example buffer.get(0) ) looks faster than calling myFloat[0]...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #3 - Posted 2003-01-28 09:07:06 »

Haven't done any tests, but I'd imagine that it is the bounds checking that is restricting the arrays? (on second thought, shouldn't Buffers have bounds checks too?)

Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #4 - Posted 2003-01-28 09:37:44 »

They have. You can look it up in the source.

See Buffer#checkBounds().

One of the first statements in FloatBuffer:

1  
    final float[] hb;


I don't think they are faster if not using them for JNI or NIO.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline TheAnalogKid

JGO Coder


Projects: 2



« Reply #5 - Posted 2003-02-12 21:37:38 »

In theory FloatBuffer (and others) should be faster if it was created as a view from a direct ByteBuffer:

1  
2  
ByteBuffer byteBuf = ByteBufferallocateDirect(9999);
FloatBuffer floatBuf = byteBuf.asFloatBuffer();

Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #6 - Posted 2003-02-13 07:36:27 »

Ok, so :

1  
2  
ByteBuffer byteBuf = ByteBufferallocateDirect(9999); 
FloatBuffer floatBuf = byteBuf.asFloatBuffer();


sould be faster than :

1  
float [] = new float[9999];


Thanks for your replies, i'm going to make a little benchmark about it.

++
Chman
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #7 - Posted 2003-02-13 12:31:53 »

Is that true? I thought that arrays of primitives were allocated to the stack and not the heap so in essence they should be the same speed.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline TheAnalogKid

JGO Coder


Projects: 2



« Reply #8 - Posted 2003-02-13 14:19:32 »

That's what I assume from the jdk 1.4 API doc and that's why I mentionned in theory:).  I haven't had time to try it yet.

We'll see Chman's results.

Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #9 - Posted 2003-02-13 14:44:44 »

Interesting results :

1  
2  
3  
4  
5  
6  
7  
8  
Allocate float buffer : 20 milliseconds
Allocate float primitive : 60 milliseconds

Fill in float buffer : 50 milliseconds
Fill in float primitive : 20 milliseconds

Get in float buffer : 40 milliseconds
Get in float primitive : 30 milliseconds


So buffers seems to be only faster when allocating memory...

++
Chman
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 368
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2003-02-13 19:26:32 »

That's kind of annoying, because they should be virtually identical. The machine code produced, after inlining and optimisation and bounds check elimination, should be exactly the same.

Grr.

Cas Smiley

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #11 - Posted 2003-02-14 01:27:35 »

Arrays even of primatives, are objectsm so they must be on the heap.
Are direct buffers zeroed like arrays have to be?

After optimization the access times should be the same. but prior to optimization buffers will have function call overhead for the accesses.

Offline leknor

Junior Member




ROCK!!!


« Reply #12 - Posted 2003-02-14 04:30:00 »

NIO Buffers are a new feature, they will get faster with future realeases of the JVM. JVM authors have had a long time to think about arrays and make them faster. Be patient.
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.

Nickropheliac (14 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!