刚学习vxWorks,今天碰到了一个问题,想请教一下各位!先谢谢了!
今天看到了一个这样的函数,是有关msgQSend的!
int DataProcess(char *pData, int DataLen)
{
char *ReceivePack = NULL;
MNREMSG msgSend;
ReceivePack = malloc(RESPONSE_PACKET_LEN);
memset(ReceivePack, 0, RESPONSE_PACKET_LEN);
memcpy(ReceivePack, pData, DataLen);
msgSend.cMsgType = 1;
msgSend.PacketLen = DataLen;
msgSend.nValue = (unsigned long)ReceivePack; /*** 传递收到数据包地址***/
/***** send a msgQ to activate the task of tMnProcess to response the received packet *****/
if (msgQSend(msgQId, (char*)&msgSend, sizeof(msgSend), NO_WAIT, MSG_PRI_NORMAL) == ERROR)
{
free(ReceivePack);
return -1;
}
return 1;
}
我的疑问是:
msgSend不是局部变量吗?当这个函数退出以后,stack不是就被回收了吗?那么这个msgSend的地址不就是无效的吗?
这样不就是有问题吗?msgQReceive接收的数据不就是不正确的吗?
------解决方案--------------------------------------------------------