Re: Practical difference between sequence and a C array

new topic     » goto parent     » topic index » view thread      » older message » newer message
ssallen said...

Hello everyone, I have been slowly working on Mic's opengl library and wrapping all the needed functions for the modern OpenGl pipeline (VBO support, matrix math, etc.) and I am finding myself doing a LOT of matrix math. Since opengl just uses a length 16 c array to store these matrices I have to constantly convert my sequences into arrays. This obviously degrades performance.

I'm thinking that it might be better to use allocate() to allocate memory to create the arrays and use those directly. If eu code needs to look at an element of the array, use peek()/poke() to do it. (Perhaps wrapped safely in a helper function that takes the array and an index).

ssallen said...

I don't really know a lot about the internals of euphoria memory management so Im curious, how much different is the memory layout of a static, single dimension, sequence of length 16 (using floating pt) than a c array of length 16?

The array that's used internally is basically an array of pointers, except that the zeroth element is used to store the length. So you're off by one.

Each pointer then points to a eu specific struct that contains the double floating point (but not the single floating point, or float32, that opengl is using).

ssallen said...

Can I make small alterations to a sequence and convert it to an array without reading each element and then poking it directly?

If it was an array of 32bit (or rather 31bit) ints, then possibly yes. Otherwise, unfortunately not. Worse, in your case you'd have the extra conversion from float64 to float32 anyways.

ssallen said...

Here is my current process:

function seq_to_matrixf(sequence s1)  -- s1 is a seq of floats of length 16	 
	atom x_array  
 
        if length(s1) != 16 then 
            return -1   -- not correct matrix dimension 
        end if 
	 
	x_array = allocate(64) -- float32s are 4 bytes each * 16 values  
  
	for i = 1 to length( s1 ) do  
    		poke( x_array + (i-1) * 4, atom_to_float32( s1[i] ) )  
	end for  
 
	return x_array 
end function 

Is there a faster way to convert same length and single dimensional sequences into arrays?

Thanks!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu