NET to GS process for a package

Source: Internet
Author: User

Let's take a look at the process of a package of shared memory first look at how the net process is handled {//packages that were just taken from the lock-free queue are encapsulated in this type of SharedataSharedata SD; sd.channel_id=pkt.channel_id; Sd.data=Pkt.data; Sd.is_data=Pkt.is_data; Sd.size=pkt.size; Auto HR= M_spsharememinter->pusha (SD);//put this package in shared memory}//specifically, how to put the shared memoryBOOLSharememinteroneway::p ushin (sharedata sd) {scoped_lock<interprocess_mutex>Lock(M_mem mirror->mutex);//process lock required, different process accessSharedataex SD2; BOOLhr =m_processmempool.getpkt (sd.size, SD2); if(!hr)return false; Sd2.size=sd.size; sd2.channel_id=sd.channel_id; Sd2.is_data=Sd.is_data; if(sd.is_data) {memcpy (Sd2.data, Sd.data, sd.size); } m_sharememque-push_back (SD2); return true;}BOOLPROCESSMEMPOOLEX::GETPKT (intLen, sharedataex&SD) {    if(Len < -)//determine from which shared memory to take from the length of the        returnm_processmempool0.getpkt (len, SD); Else if(Len < +)        returnm_processmempool1.getpkt (len, SD); returnm_processmempool2.getpkt (len, SD);}BOOLPROCESSMEMPOOL::GETPKT (intLen, sharedataex&SD) {    if(Len >m_memsize) {        //Testwchar_t tips[ -] = {0}; wsprintf (tips, L"warning100o:len:%d, memsize:%d! ", Len, m_memsize); MessageBox (NULL, Tips/*L "100o"*/, L"1ooo", MB_OK); return false; }    if(!m_queue->size ())return false; SD= M_queue->front ();//If you see this, you know why you should initialize that Shared queue.M_queue->Pop_front (); Sd.data=Convertadd (Sd.index); return true;}void* Processmempool::convertadd (intindex) {    return(Char*) M_START_ADDR + (index * m_memsize);//get the corresponding address of the shared memory pool by this index} attached: M_queue initialization code: { for(inti =0; i < M_buffer_num; i++) {Sharedataex sd; Sd.index= i;//This is the index that represents which piece of the memory poolSd.size =0; Sd.total_size=m_memsize; M_queue-push_back (SD); }}BOOLSharememinteroneway::p ushin (sharedata sd) {scoped_lock<interprocess_mutex>Lock(M_mem Mirror,mutex);    Sharedataex SD2; BOOLhr = M_PROCESSMEMPOOL.GETPKT (sd.size, SD2);//A memory address is obtained after calling Getpkt    if(!hr)return false; Sd2.size=sd.size; sd2.channel_id=sd.channel_id; Sd2.is_data=Sd.is_data; if(sd.is_data) {memcpy (Sd2.data, Sd.data, sd.size);//then copy the passed in SD memory to the memory pool in the shared memory, and this memory in SD is that m_recvbuff inside, there is a problem is this m_recvbuff why allocate 100m of memory, need so big? } m_sharememque->push_back (SD2);//then he puts the SD2 in the interactive Shared queue, noting that the memory in this area is still allocated in the shared memory pool, and M_sharememque just saves an address .    return true;}//Such a package is placed in the Shared queue.

NET to GS process for a package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.