• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            把握命運,追逐夢想

            對自己所做的事要有興趣,同時還要能夠堅持不懈

            統計

            留言簿(1)

            閱讀排行榜

            評論排行榜

            #

            同步訪問中的讀寫者問題(使用線程關鍵域)

            #include <windows.h>
            #include 
            <stdlib.h>
            #include 
            <time.h>
            #include 
            <stdio.h>
            struct CRITICAL_REGION
            {
            public:
                CRITICAL_SECTION cs;
                
            int gData;
            }
            ;
            DWORD WINAPI writer(LPVOID cr);
            DWORD WINAPI reader(LPVOID cr);


            int main(int argc,char* argv[])
            {
                DWORD targetThreadID;
                HANDLE writerThread;
                HANDLE readerThread;
                CRITICAL_REGION cr;
                cr.gData
            =0;
                InitializeCriticalSection(
            &(cr.cs));
                writerThread 
            =CreateThread(NULL,0,writer,&cr,0,&targetThreadID);
                CloseHandle(writerThread);
                readerThread 
            =CreateThread(NULL,0,reader,&cr,0,&targetThreadID);    
                CloseHandle(readerThread);
                Sleep(
            10000);
                printf(
            "end");
                
            return 0;
            }


            DWORD WINAPI writer(LPVOID cr)
            {
                Sleep(
            1000);
                DWORD result 
            = 0;
                
            int n = 1;
                ExitProcess(
            0);

                
            while(n<=10)
                
            {
                    EnterCriticalSection(
            &((CRITICAL_REGION*)cr)->cs);
                    
            if(((CRITICAL_REGION*)cr)->gData==0)
                    
            {
                        ((CRITICAL_REGION
            *)cr)->gData = n;
                        printf(
            "gData is %d\n",((CRITICAL_REGION*)cr)->gData);
                        n
            ++;
                    }

                    LeaveCriticalSection(
            &(((CRITICAL_REGION*)cr)->cs));
                    Sleep(
            100);

                }

                
            return result;
            }
            ;

            DWORD WINAPI reader(LPVOID cr)
            {
                DWORD result 
            =0;
                
            char u[6];
                
            int n = 1;
                
            while(n<=10)
                
            {
                    EnterCriticalSection(
            &((CRITICAL_REGION*)cr)->cs);
                    
            if(((CRITICAL_REGION*)cr)->gData!=0)
                    
            {
                        ((CRITICAL_REGION
            *)cr)->gData = 0;
                        n
            ++;
                        printf(
            "gData is taken away\n");
                    }

                    LeaveCriticalSection(
            &(((CRITICAL_REGION*)cr)->cs));
                    Sleep(
            50);

                }

                DeleteCriticalSection( 
            &(((CRITICAL_REGION*)cr)->cs)); 
                gets(u);
                
            return result;
            }
            ;

            posted @ 2009-08-12 18:24 把握命運 閱讀(234) | 評論 (0)編輯 收藏

            C++作業一------------模擬電腦的組裝

                 摘要: // stdafx.h : 標準系統包含文件的包含文件,// 或是經常使用但不常更改的// 特定于項目的包含文件//#pragma once#define WIN32_LEAN_AND_MEAN        // 從 Windo...  閱讀全文

            posted @ 2009-08-12 18:10 把握命運 閱讀(319) | 評論 (0)編輯 收藏

            C++作業二----實現一個棧的基本功能

                 摘要: #include "Stack.h"CStack::CStack(void){    this->m_pTopMost = new char[100];    this->m_pBottom = &(this->m_pTopMost[...  閱讀全文

            posted @ 2009-08-12 17:48 把握命運 閱讀(259) | 評論 (0)編輯 收藏

            數、字符、字符串的各種轉換方法

            //第一種方法,使用sprintf系列函數
            swprintf(buf,L"the char is %d",integer);
            sprintf(buf,
            "the char is %d",integer);
            //第二種方法
            CString str;
            str.Format(
            "5+3=%d",99);
            MessageBox(str);

            (先寫幾種,以后慢慢積累補充)

            posted @ 2009-08-11 23:32 把握命運 閱讀(91) | 評論 (0)編輯 收藏

            vc上的內存泄露調試的例子

            /*****************************************************************
             *             ?000 Microsoft Corporation                  *
             *  CRT_DBG1                                                     *
             *  This simple program illustrates the basic debugging features *
             *  of the C runtime libraries, and the kind of debug output     *
             *  that these features generate.                                *
             ****************************************************************
            */


            #include 
            <stdio.h>
            #include 
            <string.h>
            #include 
            <malloc.h>
            #include 
            <crtdbg.h>
                
            // Disable deprecation warnings.  The unsecure version of strcpy is
            // used intentionally to show off debugging features.
            #pragma warning (disable : 4996)

            // This routine place comments at the head of a section of debug output
            void OutputHeading( const char * explanation )
            {
               _RPT1( _CRT_WARN, 
            "\n\n%s:\n**************************************\
            ************************************\n", explanation );
            }


            // The following macros set and clear, respectively, given bits
            // of the C runtime library debug flag, as specified by a bitmask.
            #ifdef   _DEBUG
            #define  SET_CRT_DEBUG_FIELD(a) \
                        _CrtSetDbgFlag((a) 
            | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
            #define  CLEAR_CRT_DEBUG_FIELD(a) \
                        _CrtSetDbgFlag(
            ~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
            #else
            #define  SET_CRT_DEBUG_FIELD(a)   ((void) 0)
            #define  CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
            #endif


            int main( )
            {
               
            char *p1, *p2;
               _CrtMemState s1, s2, s3;

            #ifndef _DEBUG
            printf(
            "Skipping this for non-debug mode.\n");
            return 2;
            #endif

               
            // Send all reports to STDOUT
               _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
               _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
               _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
               _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
               _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
               _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );

               
            // Allocate 2 memory blocks and store a string in each
               p1 = malloc( 34 );
               strcpy( p1, 
            "This is the p1 string (34 bytes)." );

               p2 
            = malloc( 34 );
               strcpy( p2, 
            "This is the p2 string (34 bytes)." );


               OutputHeading( 
                  
            "Use _ASSERTE to check that the two strings are identical" );
               _ASSERTE( strcmp( p1, p2 ) 
            == 0 );

               OutputHeading( 
                  
            "Use a _RPT macro to report the string contents as a warning" );
               _RPT2( _CRT_WARN, 
            "p1 points to '%s' and \np2 points to '%s'\n", p1, p2 );

               OutputHeading( 
                  
            "Use _CRTMemDumpAllObjectsSince to check the p1 and p2 allocations" );
               _CrtMemDumpAllObjectsSince( NULL );

               free( p2 );

               OutputHeading( 
                  
            "Having freed p2, dump allocation information about p1 only" );
               _CrtMemDumpAllObjectsSince( NULL );

               
            // Store a memory checkpoint in the s1 memory-state structure
               _CrtMemCheckpoint( &s1 );

               
            // Allocate another block, pointed to by p2
               p2 = malloc( 38 );
               strcpy( p2, 
            "This new p2 string occupies 38 bytes.");

               
            // Store a 2nd memory checkpoint in s2
               _CrtMemCheckpoint( &s2 );

               OutputHeading( 
                  
            "Dump the changes that occurred between two memory checkpoints" );
               
            if ( _CrtMemDifference( &s3, &s1, &s2 ) )
                  _CrtMemDumpStatistics( 
            &s3 );

               
            // Free p2 again and store a new memory checkpoint in s2
               free( p2 );
               _CrtMemCheckpoint( 
            &s2 );

               OutputHeading( 
                  
            "Now the memory state at the two checkpoints is the same" );
               
            if ( _CrtMemDifference( &s3, &s1, &s2 ) )
                  _CrtMemDumpStatistics( 
            &s3 );

               strcpy( p1, 
            "This new p1 string is over 34 bytes" );
               OutputHeading( 
            "Free p1 after overwriting the end of the allocation" );
               free( p1 );

               
            // Set the debug-heap flag so that freed blocks are kept on the
               
            // linked list, to catch any inadvertent use of freed memory
               SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF );

               p1 
            = malloc( 10 );
               free( p1 );
               strcpy( p1, 
            "Oops" );

               OutputHeading( 
            "Perform a memory check after corrupting freed memory" );
               _CrtCheckMemory( );

               
            // Use explicit calls to _malloc_dbg to save file name and line number
               
            // information, and also to allocate Client type blocks for tracking
               p1 = _malloc_dbg( 40, _NORMAL_BLOCK, __FILE__, __LINE__ );
               p2 
            = _malloc_dbg( 40, _CLIENT_BLOCK, __FILE__, __LINE__ );
               strcpy( p1, 
            "p1 points to a Normal allocation block" );
               strcpy( p2, 
            "p2 points to a Client allocation block" );

               
            // You must use _free_dbg to free a Client block
               OutputHeading( 
                  
            "Using free( ) to free a Client block causes an assertion failure" );
               free( p1 );
               free( p2 );

               p1 
            = malloc( 10 );
               OutputHeading( 
            "Examine outstanding allocations (dump memory leaks)" );
               _CrtDumpMemoryLeaks( );

               
            // Set the debug-heap flag so that memory leaks are reported when
               
            // the process terminates. Then, exit.
               OutputHeading( "Program exits without freeing a memory block" );
               SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );
            }
            大概解釋一下,這里的函數都是什么作用:
            1、首先是剛開始的六個函數,這六個函數的作用就是讓接下來的內存調試函數輸出調試信息到控制臺。后面的函數都是實際調試內存的,如果之前調用了這六個函數,那么調試信息會輸出到控制臺。
            2、_CrtMemDumpAllObjectsSince( NULL )函數的作用是輸出目前為止,在堆中申請的空間的所有信息,包括地址,大小,內容。
            3、_CrtDumpMemoryLeaks( )函數的作用是檢測到目前為止,還有哪些堆中申請的內存沒有釋放,包括地址,大小等
            4、SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF )宏的作用是在程序結束的時候檢測堆內存是否還有泄露,作用同CrtDumpMemoryLeaks( )一樣,只不過是在所有該釋放的都結束之后,進行最后的檢查。
            (未完,以后補充)

            posted @ 2009-08-11 19:49 把握命運 閱讀(789) | 評論 (0)編輯 收藏

            C++和C語言在文件操作打開方式上的對應

            //這是C++文件打開的部分實現fiopen.cpp文件的一個函數,看了就明白了
            _CRTIMP2_PURE FILE *__CLRCALL_PURE_OR_CDECL _Fiopen(const _Sysch_t *filename,
                ios_base::openmode mode, 
            int prot)
                
            {    // open a file with native name
                static const _Sysch_t *mods[] =
                    
            {    // fopen mode strings corresponding to valid[i]
                    _SYSCH("r"), _SYSCH("w"), _SYSCH("w"), _SYSCH("a"),
                    _SYSCH(
            "rb"), _SYSCH("wb"), _SYSCH("wb"), _SYSCH("ab"),
                    _SYSCH(
            "r+"), _SYSCH("w+"), _SYSCH("a+"),
                    _SYSCH(
            "r+b"), _SYSCH("w+b"), _SYSCH("a+b"),
                    
            0}
            ;

                
            static const int valid[] =
                    
            {    // valid combinations of open flags
                    ios_base::in,
                    ios_base::
            out,
                    ios_base::
            out | ios_base::trunc,
                    ios_base::
            out | ios_base::app,
                    ios_base::
            in | ios_base::binary,
                    ios_base::
            out | ios_base::binary,
                    ios_base::
            out | ios_base::trunc | ios_base::binary,
                    ios_base::
            out | ios_base::app | ios_base::binary,
                    ios_base::
            in | ios_base::out,
                    ios_base::
            in | ios_base::out | ios_base::trunc,
                    ios_base::
            in | ios_base::out | ios_base::app,
                    ios_base::
            in | ios_base::out | ios_base::binary,
                    ios_base::
            in | ios_base::out | ios_base::trunc
                        
            | ios_base::binary,
                    ios_base::
            in | ios_base::out | ios_base::app
                        
            | ios_base::binary,
                    
            0}
            ;

                FILE 
            *fp = 0;
                
            int n;
                ios_base::openmode atendflag 
            = mode & ios_base::ate;
                ios_base::openmode norepflag 
            = mode & ios_base::_Noreplace;

                
            if (mode & ios_base::_Nocreate)
                    mode 
            |= ios_base::in;    // file must exist
                if (mode & ios_base::app)
                    mode 
            |= ios_base::out;    // extension -- app implies out

                mode 
            &= ~(ios_base::ate | ios_base::_Nocreate | ios_base::_Noreplace);
                
            for (n = 0; valid[n] != 0 && valid[n] != mode; ++n)
                    ;    
            // look for a valid mode

                
            if (valid[n] == 0)
                    
            return (0);    // no valid mode
                else if (norepflag && mode & (ios_base::out || ios_base::app)
                    
            && (fp = _Xfsopen(filename, _SYSCH("r"), prot)) != 0)
                    
            {    // file must not exist, close and fail
                    fclose(fp);
                    
            return (0);
                    }

                
            else if (fp != 0 && fclose(fp) != 0)
                    
            return (0);    // can't close after test open
                else if ((fp = _Xfsopen(filename, mods[n], prot)) == 0)
                    
            return (0);    // open failed

                
            if (!atendflag || fseek(fp, 0, SEEK_END) == 0)
                    
            return (fp);    // no need to seek to end, or seek succeeded

                fclose(fp);    
            // can't position at end
                return (0);
                    }

            posted @ 2009-08-11 18:52 把握命運 閱讀(627) | 評論 (0)編輯 收藏

            整理一下網上的那個vc遍歷網頁的程序

                 摘要: #include <stdio.h>#include <tchar.h>#include<iostream>#include<exdisp.h>#include <atlbase.h>  #include <atlcom.h>#include<mshtml.h&...  閱讀全文

            posted @ 2009-08-10 17:40 把握命運 閱讀(882) | 評論 (0)編輯 收藏

            C++編程練習作業

                 摘要: //Computer.h#pragma once#include"CPU.h"#include"Memory.h"#include"MainBoard.h"#include"Monitor.h"class CComputer{private:    CCPU m_cpu;    CMemo...  閱讀全文

            posted @ 2009-08-07 16:41 把握命運 閱讀(302) | 評論 (0)編輯 收藏

            C++編程練習1

             

            C++編程練習1

            實現一個計算機的Class的層次結構

            l         CPU

            Method :設定廠商名稱

                   :取得廠商名稱

                   :取得價格

            :設定主頻

                   :取得價格實現方法:根據主頻的范圍和廠商確定(自己自由發揮)

            l         Memory

            Method :設定廠商名稱

                   :取得廠商名稱

                   :取得價格(自己自由發揮)

            :設定大小

                   :取得價格實現方法:根據內存大小的范圍和廠商確定

            l         MainBoard

            Method :設定廠商名稱

                   :取得廠商名稱

                   :取得價格(自己自由發揮)

            :取得價格實現方法:根據廠商確定

            Plug(CCPU*,CMemory* )

            SelfCheck() 檢察是否plug過正確的CPU, Memory

            l         Monitor

            Method :設定廠商名稱

                   :取得廠商名稱

                   :取得價格

                   :設定大小

                   :設定類型:一般。液晶

                   :取得價格實現方法:根據大小,是否液晶和廠商確定(自己自由發揮)

            類計算機:

                包含以上幾個類的成員

            Method :設定CPU主頻

            :設定CPU廠商(A,B,C)

                   :設定Memory大小(128256512

            :設定Memory廠商(A,B,C)

                   :設定顯示器大小(14151719),類型(一般,液晶)

                   :設定顯示器廠商(A,B,C)

                   :設定主版的廠商(A,B,C)

            :察看整機價格(打印到屏幕)

                   :察看配置(打印到屏幕)

                   Init() (調用MainBoard.Plug())

                   Start() (調用MainBoard.SelfCheck() )

            l         Computer類:包含上面幾個類的對象。

            寫一個小程序,動態創建一個10Computer的數組,設定察看每一臺的配置,計算總價格等。

            要求正確的釋放對象的數組。

             

             

             

            posted @ 2009-08-07 13:29 把握命運 閱讀(634) | 評論 (0)編輯 收藏

            C++構造函數中必須使用參數列表的三種情況

            const類型成員
            引用類型成員
            類類型成員

            posted @ 2009-08-07 11:21 把握命運 閱讀(429) | 評論 (0)編輯 收藏

            僅列出標題
            共5頁: 1 2 3 4 5 
            欧美无乱码久久久免费午夜一区二区三区中文字幕 | 品成人欧美大片久久国产欧美| 99久久免费国产精品特黄| 精品国产91久久久久久久a| 久久99精品久久久久久hb无码 | 久久WWW免费人成—看片| 久久无码人妻一区二区三区| 久久精品国产99久久久古代| 久久午夜福利无码1000合集| 2021国内精品久久久久久影院| 亚洲精品乱码久久久久久不卡| 日本亚洲色大成网站WWW久久| 亚洲国产精品一区二区三区久久 | 亚洲国产精品无码久久久秋霞2 | 国产成人综合久久精品红| 伊人久久五月天| 色欲av伊人久久大香线蕉影院| 99久久99久久精品国产片果冻 | 精品无码人妻久久久久久| 久久综合给合综合久久| 久久亚洲精品成人无码网站| 久久久久亚洲AV片无码下载蜜桃 | 99国产欧美久久久精品蜜芽 | 日本久久久精品中文字幕| 国产精品美女久久久久av爽 | 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲国产另类久久久精品小说| 精品久久久久久久久午夜福利| 日本免费久久久久久久网站| 日韩欧美亚洲国产精品字幕久久久| 99久久这里只精品国产免费| 久久精品亚洲中文字幕无码麻豆 | 国产精品美女久久久免费| 婷婷久久综合九色综合九七| 久久久无码人妻精品无码| 久久精品国产亚洲一区二区三区| 欧美日韩精品久久免费| 一级做a爰片久久毛片人呢| 久久精品青青草原伊人| 久久精品国产99久久丝袜| 久久久女人与动物群交毛片|