deepstream-user-metadata-app limited to only char or int type metadata?

I am trying to attach custom type metadata, like string in deepstream_sdk_v4.0_jetson/sources/apps/sample_apps/deepstream-user-metadata-test/deepstream_user_metadata_app.c . For this, I have modified the set_metadata function like this:

void *set_metadata_ptr()
  int i = 0;
  gchar *user_metadata = (gchar*)g_malloc0(USER_ARRAY_SIZE);
  char str[20] = "string";

  g_print("\n**************** Setting user metadata array of 16 on nvinfer src pad\n");
//  for(i = 0; i < USER_ARRAY_SIZE; i++) {
    user_metadata[0] = str;

    user_metadata[1] = 'K'; // works fine with single character or integer type variables

    g_print("user_meta_data [%d] = %s\n", 0, user_metadata[0]);

   g_print("user_meta_data [%d] = %c\n", 1, user_metadata[1]);
//  }
  return (void *)user_metadata;

It doesn’t work, results in segmentation fault. I need some different types of variable as user_metadata, like string or float. Could anyone suggest how to attach different type of variable like float, string etc as user_metadata?

I think you cannot assign the char pointer to char type.
user_metadata[0] = str;

For example, I want to attach float type variable. Why it’s not attaching float but attaching integer?

user_metadata[0] = (int) 156;

It works fine until the value is less than 255. But

user_metadata[0] = (float) 1.56;

It doesn’t work because the return value is always 0.00


You are trying to assign float to char. It won’t work. What do you expect to get back when you assign 1.56 to char?

I wonder how int has been assigned to char as in this line?

user_metadata[0] = (int) 156;

How this is even working? Could you please explain? @mipko

I think mipko has explained very clearly.
char only has 8 bit, so you can assign some int value to char, this is the basic syntax problem.

char is 8-bit (1 byte) large. It can be observed as an int.
Depending if it is signed or unsigned it can hold following int values:

char	        1 byte	-128 to 127 or 0 to 255
unsigned char	1 byte	   0 to 255
signed char	1 byte	-128 to 127

So try to assign 4242 to user_metadata[0] and check what you get.

On the other hand float is 4 bytes long which means any float requires four elements of your array to represent that float.

float	4 byte	1.2E-38 to 3.4E+38	6 decimal places

At the end you could use your array to store floats with pointer arithmetic, but it is not the way you should do it. Nevertheless if you have N floating point numbers your array should be 4*N large.