C Statistics API では、配列にメモリーを割り当てるために 2 つのメソッドを使用します。
ba_list_interfaces() と ba_list_class_names() 関数を使用する場合は、必ずバッファーにクラス数に応じた十分なメモリーを割り当てる必要があります。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);
}
|
ba_list_interface_config()、ba_list_classes()、および ba_get_flow_stats() 関数を使用する場合、メモリーは自動的に割り当てられます。ただし、あとで ba_free() 関数を呼び出して、このメモリーを解放する必要があります。