How to memset float4 data?

Hi! Initially I create a register array and then calculate it, now, I want to re allocate it as all 0. Maybe the fastest way is using memset? But note that this is float4! How to use memset here? Thank you!!!

	float4 f4_zero = make_float4(0, 0, 0, 0);
	float4 c[8][2] = { { f4_zero} };

        memset(c, f4_zero, sizeof(float4)); //??????????

Thank you!!!

the 2nd argument of memset always takes a char. What you want is

memset(c, 0, 8*2*sizeof(float4));

sizeof(c) will be identical to 8*2*sizeof(float4) and should be used instead.

Generally you cannot initialize an array of floats with a desired float value using memset unless the desired value is 0. A float value of 0.0f corresponds to a sequence of 4 null bytes. The workaround for other values is to use a for loop and setting the array elements to the desired value.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.