PDA

View Full Version : Lifetimes of params and return values from NDI SDK (C++, windows)



roddyp
09-23-2017, 10:39 AM
Hi all,

Just wondering if there were specific guidelines for lifetimes of the string/struct params and returned structs with the NDI SDK?

Example #1:-


Router(const std::string &name, const std::string &groups = "")
{
NDIlib_routing_create_t params;
params.p_ndi_name = name.c_str();
params.p_groups = groups.c_str();
instance = NDIlib_routing_create(&params); // Is it safe for the 'params' struct to go out of scope now? What about the char array pointed to by p_ndi_name
}

Example #2:


const NDIlib_source_t* p_sources = NDIlib_find_get_current_sources(instance, &no_sources);

How long is p_sources valid for (presumable the caller shouldn't free() it) - and is this thread-safe?

brianbrice
09-25-2017, 09:40 AM
Is it safe for the 'params' struct to go out of scope now? What about the char array pointed to by p_ndi_name

That is correct.


How long is p_sources valid for (presumable the caller shouldn't free() it) - and is this thread-safe?

It'll be valid until the next call to NDIlib_find_get_current_sources or NDIlib_find_destroy, so probably not thread-safe if you're using the same instance across multiple threads.

roddyp
09-27-2017, 10:54 AM
It'll be valid until the next call to NDIlib_find_get_current_sources or NDIlib_find_destroy, so probably not thread-safe if you're using the same instance across multiple threads.

Great - thankyou!