VC serial control programming, solving the increasing problem of memory

xiaoxiao2021-03-06  39

VC serial control programming, resolving the increasing number of memory: Name: Wang Chaojie If you need to reprint, please contact the author. Chaojie2003@yahoo.com.cn

Development Environment: VC6 Windows 2000 Explanation: Many people often encounter when serial accepted data is relatively large, from Windows 2000 Task Manager, can see the memory of the program occupied by the program. Increase, I have to transfer the API from the new writing. This article mainly solves this problem. When writing a serial control to receive data, it is written: // Initial setting m_mscomm.setcommport (1) // Open COM1M_MSCOMM.SETPORTOPEN (TRUE); / / Open the serial port m_mscomm.setSettings ("115200, n, 8, 1"); // Serial port parameter setting m_mscomm.setinputMode (1); // CominputModeBinary Set Binary Buffer Input mode m_mscomm.sethreshold (5); // Each received 5 characters excited oncomm () event m_mscomm.setinputlen (5); // read 5 characters // receive data Void ccomdlg :: oncomm () {variant variant_inp; ColesafeArray Safearray_inp; Long Len, K; Byte RxData [5]; // Set the BYTE array cstring strTemp; switch (m_mscomm.getCommEvent ()) {case 2: // Event value 2 indicates that the receiving buffer has character variant_inp = m_mscomm.getinput (); // Read buffer ------------------------------- * SafeArray_inp = variant_inp; // variant type variable converted to COLESAFEARRAY Type Variable Len = SafeArray_inp .Getonedimsize (); // Verify resulting the valid data length assert (len == 5); for (k = 0; k > 8) & 0xff; strbuf [1] = Tempbyte; // Address low tempbyte = para1 & 0xff; strbuf [2] = Tempbyte; // data high tempbyte = (para2 >> 8) & 0xff; strbuf [3] = tempbyte; // Data Low Tempbyte = Para2 & 0xFF ; strbuf [4] = Tempbyte; Outbuf.setsize (5); for (int i = 0; i <5; i ) Outbuf [i] = strbuf [i]; varoutput = Outbuf; m_mscomm.setput (varoutput);} The problem is on the Variant type variable. When the line is executed, the variant type variable will increase the memory, and can be solved by the following method: void ccomdlg :: oncomm () {Long Len, K; Colevariant MyVar; ColesafeArray SafeArray_inp; Byte RxData [5];

转载请注明原文地址:https://www.9cbs.com/read-51639.html

New Post(0)