2014-02-17 55 views

回答

3

不,sendmsg()不释放传入的内存。它不可能这样做,因为该内存可能不是来自malloc()。你可以在sendmsg()之后的任何时候拨打free(),因为系统已经做好了必要的拷贝。

+0

由于某种原因,我发现“......内存可能甚至不是来自malloc()”的线条“幽默”。 –

0

不,你不能释放它。它只是发送使用msghdr结构的内存字节。

通常你分配内存写入的msghdr iovec的,并呼吁SENDMSG将它转移作为,

char buffer[SIZE]="DATA"; // Data to send into buffer 
struct iovec io;   // Segment which will store outgoing message 
struct msghdr msgh;  // msghdr structure 
... 
io.iov_base = buffer;  // Specify the components of the message in an iovec 
io.iov_len = SIZE; 
msgh.msg_iov = &io; 
... 
sendmsg(fd,&msgh,0);  // send msg which just send msg in a iovec buffer 
+0

谢谢。我现在明白了。再次感谢。 –

相关问题