Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: Re: [OMPI devel] mca_base_component_var_register() MCA_BASE_VAR_TYPE_STRING
From: Hjelm, Nathan T (hjelmn_at_[hidden])
Date: 2014-02-14 11:38:38


On Friday, February 14, 2014 9:31 AM, devel [devel-bounces_at_[hidden]] on behalf of Adrian Reber [adrian_at_[hidden]] wrote:
> To: devel_at_[hidden]
> 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