Solaris Bandwidth Manager 1.6 Developer Guide

Memory Handling

The C Statistics API uses two methods for allocating memory for arrays.

When using the ba_list_interfaces() and ba_list_class_names() functions, you must always allocate sufficient memory for the buffer, the size of which is dependent on the number of classes. For example, when using ba_list_interfaces():

nintface = ba_get_num_interfaces();
if (nintface > 0) {
	interfaces = (ba_name_t *) calloc(nintface, sizeof ba_name_t);
	if (ba_list_interfaces(interfaces) != -1) {
	/* process interfaces .. */
} else {
	/* error handling */
}
	free(interfaces);
}

When using the ba_list_interface_config(), ba_list_classes() and ba_get_flow_stats() functions, memory is allocated automatically. However, in this case the user must call the ba_free() function afterwards, in order to free this memory.