ACE 类学习1: ACE_Message_Block

 C++NPv1 4.2 节的示例,在windows + vc2005 上运行调试学习了下,感觉像个链表容器。

#include "ace/ACE.h" #include "ace/OS.h" #include "ace/Message_Block.h" #define BUFSIZE 8 int main(int argc, char * argv[]) { ACE_Message_Block * head = new ACE_Message_Block(BUFSIZE); ACE_Message_Block * mblk = head; for(int i = 0; i < 3; i++) { ssize_t nbytes = ACE::read_n(ACE_STDIN, mblk->wr_ptr(), mblk->size()); if(nbytes <= 0) break; // Break out at EOF or error. // Advance the write pointer to the end of the buffer. mblk->wr_ptr(nbytes); // Allocate message block and chain it at the end of list. mblk->cont(new ACE_Message_Block(BUFSIZE)); mblk = mblk->cont(); } // Print the contents of the list to the standard output. for(mblk = head; mblk != 0; mblk = mblk->cont()) ACE::write_n(ACE_STDOUT, mblk->rd_ptr(), mblk->length()); head->release(); // This releases all the memory in the chain. return 0; }

 

你可能感兴趣的:(c,windows,list)