Results 1 to 5 of 5
  1. #1
    maxkiva is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default FloatBuffer and 'put( float[] src )'

    Hi All,
    I am trying to use FloatBuffer created on top of ByteBuffer and having problems with using 'put ( float[] src )' method. 'put' for individual values seems to be working fine. Heres is the sample code:

    Java Code:
    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;
    import java.nio.FloatBuffer;
    
    public class TestFloatBuffer
    {
    	private static final int COUNT = 3;
    	private static FloatBuffer _fbb = null;
    	
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args)
    	{
    		ByteBuffer tbb = ByteBuffer.allocateDirect( COUNT * 4 * 3); 
    		tbb.order(ByteOrder.nativeOrder());
    		_fbb = tbb.asFloatBuffer();
    	    float[] src = 
    			{ 	0.0f, 1.0f,0.0f,
    	    		1.0f,-1.0f,0.0f,
    	    	   -1.0f-1.0f,0.0f };
    	    _fbb.put( src );
    		_fbb.position(0);
    		for( int i = 0; i < 9; ++i )
    		{
    			System.out.println( "Index :" + i + ", val: " + _fbb.get(i) );
    		}
    	}
    
    }

    It does not print what is in 'src'.

    I use:
    $ java -showversion
    java version "1.6.0_16"
    Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
    Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode

    and

    $ javac -version
    javac 1.6.0_21

    on Linux

    I came across this bug report from a while back which looks similar, but it is reported as fix-delivered.
    http://bugs.sun.com/bugdatabase/view...bug_id=6550579

    Is this a known problem or have I got something wrong ?
    Thanks

    Max
    Last edited by Fubarable; 08-08-2010 at 11:56 AM. Reason: Moderator edit: italics removed and code tags added

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default

    I ran your code on Java 1.6.0_20-b02 and it ran fine; b.t.w. you're missing a comma in the third line of your array initialization.

    kind regards,

    Jos

  3. #3
    maxkiva is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default How embarrasing

    Thanks Jos,

    that was that coma, should not have posted this :-P :-)

    thanks again
    Max

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by maxkiva View Post
    Thanks Jos,

    that was that coma, should not have posted this :-P :-)

    thanks again
    You're welcome of course; indeed -1.0f-1.0f results in a single float -2.0f and your array ends up having eight elements. Add more spaces for readability ;-)

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Moderator edit: italics tags removed and code tags added to aid readability. To learn to do this yourself, please check out the links in my signature.

    Much luck and welcome!

Similar Threads

  1. string to float
    By Sungron in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 09:23 AM
  2. Working with float
    By dardar in forum New To Java
    Replies: 8
    Last Post: 01-27-2010, 08:29 PM
  3. java java.nio.FloatBuffer
    By sardare in forum Advanced Java
    Replies: 2
    Last Post: 04-24-2009, 10:33 PM
  4. Float vs. Double
    By javanub in forum New To Java
    Replies: 1
    Last Post: 11-23-2008, 12:11 PM
  5. Class float
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •