Skip to content

Provide a code example for the info list #505

@abouteiller

Description

@abouteiller

While working on #492, we thought that adding an example on how to use lists could be valuable.

@rhc54 proposed the following example

           I believe you asked me to provide a code example for the info list - here is a typical usage:
void *head;
pmix_status_t rc;
pmix_data_array_t darray;
pmix_info_t *info;
size_t ninfo;

// initialize the list
head = PMIx_Info_list_start();

// add something to the end of the list
rc = PMIx_Info_list_add(head, PMIX_CONNECT_TO_SYSTEM, NULL, PMIX_BOOL);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// prepend something to the list
rc = PMIx_Info_list_prepend(head, PMIX_TCP_REPORT_URI, "filename", PMIX_STRING);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// convert the list to an array of info
rc = PMIx_Info_list_convert(head, &darray);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// cleanup the list
PMIx_Info_list_release(head);

// define pointer to the array of info for use
info = (pmix_info_t*)darray.array;
ninfo = darray.size;

Doesn't cover all the APIs - but is this sufficient? I could expand to cover more APIs, but this really is the most common usage.

Originally posted by @rhc54 in #492 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions