Solved

Slow CString creation

Posted on 2008-06-09
8
311 Views
Last Modified: 2013-11-20
After I collect up to 600,000 points of data I have to process each point into a text string and display it in an edit control and/or save it as a text file, but as I process the string the processing gets very slow very soon. I update the process after every 2k points and it gets noticabley slower after each set, untill after 10,000 it is unacceptably slow.

What is going on and what can I do to remedy?



for( i=0; i<m_DataCount; i++ )
	{
		MSG msg;
		while( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
		{
			AfxGetApp()->PumpMessage();  // does a ::GetMessage() (waits...)
		}
// VOLTAGE
		cdword._dword = dwArray[i];
		wVoltage = cdword.word1;
		if( wVoltage < 100 )
			break;
	// CURRENT
		wCurrent = cdword.byte1 & 0xFC;
 
		f = wVoltage;
		str.Format("%.3f\t", f / 1000 );
		strData += str;
 
		j = wCurrent;
		f = j;
		str.Format("%.3f\t", f / 100 );
		strData += str;
 
		j = wTemperature;
		str.Format("%d\r\n", j);
		strData += str;
 
		if( i % 2000 == 0 )
		{
			str.Format("Logging complete\r\n\r\nProcessing data please wait... %dk points", i /1000 );
			m_editData.Clear();
			m_editData.SetWindowText( str );
		}
	}
	m_editData.SetWindowText( strData );

Open in new window

0
Comment
Question by:EnergyStorage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 21748945
strData += str

As the contents of strData are continually growing I suspect you have memory allocation/copy problems.

Reduce the number of times you perform the 'strData += str' action.
0
 

Author Comment

by:EnergyStorage
ID: 21752965
I knew it was due to the constant changing of CString buffer size and I solved it myself using CString function GetBufferSetLength.

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 21753118
excerpt of question
>>What is going on

later comment by questioner after a comment suggesting where the problem could lie and a solution
>>I knew it was due to the constant changing of CString buffer size

Seems to be some mismatch of information in those two statements.
0
 

Author Comment

by:EnergyStorage
ID: 21798552
a21748945 was not a solution.

I said "What is going on and how do I remedy this. Not Doing what need to be done is not a remedy.

I found the remedy on my own as I said above by using the CString function GetBufferSetLength().

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 21800165
In your original question you stated you did NOT know what was slow in your code.  When you know that then you can then remedy it.
I pointed out what I thought was slow and one potential change to improve the performance.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 73
How to know only "File created" with EventLog 3 35
Detect file exist or not 3 203
Problem to App 4 120
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question