[committed] BufferUtils.getFloatArray Method Addition

Wondering if we could add the following method to com.jme.util.geom.BufferUtils



    /**
     * Create a new float[] array and populate it with the given FloatBuffer's
     * contents.
     *
     * @param buff
     *            the FloatBuffer to read from
     * @return a new float array populated from the FloatBuffer
     */
    public static float[] getFloatArray(FloatBuffer buff) {
        if (buff == null) return null;
        buff.clear();
        float[] inds = new float[buff.limit()];
        for (int x = 0; x < inds.length; x++) {
            inds[x] = buff.get();
        }
        return inds;
    }



It is a very small change (which matches almost identically with getIntArray), but would be ncie for my project.  It is easier than creating a method in a utility class solely for my project.

Would this change be OK?

Sounds reasonable.



But be aware that using such methods should be avoided. Copying data should be done only if really necessary.

Yeah - it would be better to be able to just call the '.array()' method on the buffer…but its not always guaranteed to work.



I understand why its not always supported…but it still seems to me like they should have put a method like this in the base FloatBuffer class in the cases where it wasn't 'supported'.  I somehow doubt that I could get them to change that behavior though  :stuck_out_tongue:

thorst said:

Yeah - it would be better to be able to just call the '.array()' method on the buffer...

true. But even better would be to avoid use of that as well :P

Totally agree - except the native code I'm trying to pass the buffer to needs a float[] and an int[].

It has been a few days - haven't seen any issues.  Is there anything special I need to do to commit it.  Do I need SVN permission?

Yes. As described in the last news-item, you need to send an e-mail to info@jmonkeyengine.com and request SVN access. You also need to specify your gmail address as that will be your username to the jMe 2.0 googlecode repo.