On Friday, February 14, 2014 9:31 AM, devel [[email protected]] on 
behalf of Adrian Reber [[email protected]] wrote:
> To: [email protected]
> Subject: [OMPI devel] mca_base_component_var_register() 
> MCA_BASE_VAR_TYPE_STRING
> 
> I am trying to find out how to deal with string variables. Do I have to
> allocate the memory before calling mca_base_component_var_register() or

No, you can provide any initial value including NULL. If you allocate memory 
you will have to free it your self.

> not? It seems it does a strdup() meaning it has to be free()'d while
> closing the component. Looking at other occurrences of string variables

The variable system handles this for you. It will strdup the string value you 
provide and free it when your component goes away. It will store the allocated 
string in the pointer you provide so DO NOT free it yourself.

Ex.

foo = strdup ("foo");
mca_base_var_register (..., &foo);

free (foo);

Is not allowed nor recommended. This would be correct:

foo = "foo";
mca_base_var_register (..., &foo);

Also note that the storage you provide must be accessible as long as the 
variable is valid. So, it may not be on the stack.

-Nathan

Reply via email to