代码片段如下:
一、代码逐步解析
gVrrpInstance.operEntryTbl = (vrrpOperEntry_t *)calloc(gVrrpInstance.maxOperNum, sizeof(vrrpOperEntry_t));
if (gVrrpInstance.operEntryTbl == NULL)
{
printf("[VRRP]: vrrp init error, failed to calloc memory for global oper entry table.\r\n");
goto ERROR_RETURN;
}
分配操作条目池(操作对象池)
-
目的:创建一个操作对象表(operation entry table),用于管理 VRRP 实例或虚接口的运行时数据结构。
-
使用
calloc
是为了初始化为全 0,避免结构体中成员存在未初始化状态。
INIT_LIST_HEAD(&gVrrpInstance.operFreeTbl);
INIT_LIST_HEAD(&gVrrpInst