Visual C++ :: How To Reduce High CPU Usage Caused By Receiver Thread Of CAN Messages

Feb 13, 2013

I am writing a program which handles the CAN messages Received from BUS.My code is taking almost 60% of CPU usage.

View 14 Replies


ADVERTISEMENT

C# :: High RAM Usage On Postback Caused By Datatable

Dec 23, 2014

I basically have a listbox that has postcode areas i.e : AE,CW,GU etc etc.

The user selects this and then a postback occurs - an sql statement is builts and a database query operation is performed and the results are returned to a datatable called tempdata.

So far so good. I then need to loop through this datatable and copy the records to my main viewstate datatable which is the datasource for google maps api.

DataTable tempstore = GetData(querystring, "");
//check tempstore has rows otherwise add defaultcust as default otherwise map will be blank
if (tempstore.Rows.Count == 0)
{

[Code].....

So my main datatable can grow and grow as users add more postcodes. However when it gets to around 500 rows or so I get a huge memory spike only on postback and then it settles back down.

My ram usage goes from 2gb to 3gb and if even more postcodes is selected it maxes the memory and crashes my pc.

If I remove the:

dtpc.Importrow(row);

the memory spike goes completely, obviously because the main datatable has no rows. I thought you only run into memory issues when you have thousands of rows?

View 1 Replies View Related

Visual C++ :: How To Reduce Size Of Object

Feb 10, 2014

I am using Visual C++ to write an app. I write CMyObject class and may allocate a lot of instances of CMyObject object, so I want to reduce the size of CMyObject class.

What I can figure out to do is:

1. I can use the following code to get the accurate size used by a single instance of CMyObject object:

CMyObject Object;

//Get the size of memory allocated for CMyObject object
int nSize = sizeof(Object);

is that correct?

2.To reduce the size of CMyObject, I have several ideas:

(1)Change member function to static member function if it is possible, since each member function will take some spaces in the instance of CMyObject.

(2)Change virtual member function to member function if it is possible, since virtual member function may take more spaces.

(3)Eliminate unnecessary member variables to reduce spaces.

(4)Finally, if (1), (2) and (3) does not work well, then change CMyObject from class to a struct that only contains some member variables, thus will eliminate the spaces allocated for constructor and destructor of a class.

View 2 Replies View Related

Visual C++ :: Read Table And Get All PNAME Into Combobox - Reduce Query Execution Time

Nov 14, 2014

My table:

Code:
Database name: test & Table name : Profilemaster
+-----+--------+
| PID | PNAME |
+-----+--------+
| 1 | APPLE1 |
| 2 | APPLE2 |
| 3 | APPLE3 |
| 4 | APPLE4 |
| 5 | APPLE5 |
| 6 | APPLE6 |
| 7 | APPLE7 |
| 8 | APPLE8 |
| 9 | APPLE9 |
| 10| APPLE10 |
+-----+--------+

I like to read the table and get the all PNAME into the combo box.

Using the below code i can read the table, but while loop takes 2 seconds to read 10 records in the Profilemaster table.
How can i reduce the reading time?

My Code is
void MainScreen::OnreadProfileName() {
CDatabase database;
CString SqlString;
CString sDsn;
CString pname;

sDsn.Format("Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;Database=test;User=root;Password=client;Option=4;");

[Code] ....

Is any other way to reduce the query execution time?

View 6 Replies View Related

Visual C++ :: CPP High Frequency Trading

Jul 15, 2014

I have taken a keen interest in writing trading programs. I have some Python background, a little C# but no C++.

The example below was provided in a book on HFT and I would love to see how the results look. I was hoping that I would just compile it and away you go!

That didn't happen. To start with the author listed this as a function, so I converted it to a main program. Still having issues with my path and where to see the output. Here it is..

Code

void HFT_AvellanedaStoikov() {
FILE* fin, *fout;
double lambda_a, lambda_b, d_lambda_a, d_lambda_b;
int hh = 0, mm = 0, ss, nb = 0, na = 0, prevnb = 0, prevna = 0, prevm = 0;
double bid, ask, prevbid = 0, prevask = 0;
char * p1, *p2, buffer[1024], fname[512];

[Code] .....

Here is some data:

14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
.... and so on ....

View 3 Replies View Related

Visual C++ :: IE WebBrowser Not Sending Some Redrawing Messages

Aug 22, 2013

I have a property sheet view with few property pages. One of this property page contains a HTML representation via a CHtmlView derived class.

Initially, the .html file is correctly rendered. The problem is that sometimes switching between properties pages sometime the html file is not redraw. The behavior appears randomly.

According to Spy++ in such situation some Windows messages are not sent by WebControl (Internet Explorer_Server layer): WM_ERASEBKGRD, WM_PAINT or WM_NCPAINT.

Approaches such Q179421 or Q183161 are not useful. My machine runs IE 10.

The windows hierarchy is: Shell Embedding -> Shell DocObject View -> Internet Explorer_Server.

Any workaround that would determine Internet Explorer_Server layer to send these messages always?

View 4 Replies View Related

Visual C++ :: Intercept Messages Sent To Controls On A Dialog

Apr 8, 2013

If it is possible, I'd like to know how to intercept messages sent to controls on a dialog. I'm working on a large application with a large number of dialogs, each with a number of controls on the dialog. I need to be able to intercept messages sent to these controls so that I can determine if the controls really need to take action on these messages. I could subclass each control and override the specific event handlers but due to the volume of controls in the application this could take a very long time, will introduce risk if controls are missed, and will increase maintenance costs. What I want to do is create a class which is derived from CDialog and each of the dialogs in the application would then be derived from this new dialog class. The new dialog class would intercept messages sent to any control on the dialog and if the dialog decides that the control should do something then the dialog will pass the message on to the control.

example:
CExistingDialog is derived from CNewDialog is derived from CDialog

CExistingDialog has a number of controls. When the code in CExistingDialog calls CWnd::EnableWindow on one of these controls I want CNewDialog to intercept the message, determine what should be done with the message, and then pass it on to the control.

I'm not very familiar with the messaging framework. I've tried overriding a few of the methods of CNewDialog but none of them ever receive the message to enable the window. I assume this is because the message is sent directly to the child window (the control).

Is there any way to intercept these messages? I don't know much about hooks either but is this a possible option?

View 8 Replies View Related

Visual C++ :: Get Maximum Memory Usage Of App?

Apr 21, 2013

I use Visual C++ to write a native C++ application. How to know the maximum memory it will use during its execution?

View 5 Replies View Related

Visual C++ :: Usage Of Critical Section

Dec 11, 2012

I am using a thread in my application .. A DLL is written for In and Out instructions for hardware ICS and to read FIFO.

My code is

CCriticalSection crdll , crsec ;
UINT ThreadReceiveData(LPVOID param) {
for ( ; ; ) {
if (bTerminate) break; // bTerminate = 1 in Doc template destructor
crdll.Lock();

[Code] ....

I am confused , how and when I should use Ctitical Section ? The program works fine but I am not happy as this is main routine of the program and I have not understood it properly.

View 10 Replies View Related

Visual C++ :: MFC Proper Usage Of Sending Message To Dialog To Activate

Jan 7, 2015

I have finally got around to developing C++ & MFC using Visual Studio 2012, to build a full GUI Windows application (not sure if I have made the right choice). Though admittedly in two months time I do have a dialog window at my beck and call.

Now I have discovered a flaw (suspect) partially caused by the design of this program not all following the same principles, nor written by the same people and long predates me. Let describe the situation.

I have a dialog I have created as a class which has a combo box. The list of items are populate during the OnInitDialog() function just fine, except if the file where the detail is not yet read from that combo box would not have any items other than the default. This is to be expected in the use of the program, so fine.

However, if the dialog (modeless) was already open and active, when the user went up to and selected the menu command (main window) to read that file that CPtrList data structure that held that data would not populate that Combo box on my dialog.

So what I would like when I am done reading the files contents is to detect if my dialog is opened and if so send it a message to Activate (force a call to OnActivate()). I have gone to the event list for the dialog and exposed this event handler from the resource editor just fine.

I see the syntax of OnActivate() is

void MyClass::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimalized);

So nState is an Unsigned Int of the current state of the thread/window (not sure)?

CWnd* pWndOther is the CWnd of my other Window that wants my dialog to activate I think which is the main application since it was on the a menu that this function was called to read the file.

bMinimalized is whether my dialog is mimalized(?)

View 10 Replies View Related

C++ :: Crash Caused By 2D Array?

Nov 6, 2012

I have a function such that one of its parameters is a 2D array of type int. The parameter is defined as follows:

[code]
int topoGraph [][MAX_VERTICES]
[code]

However, the following code snippet from the body of the function crashes at the specified line:

Code :
if( counter >= 4 && !adjMatrixAlreadySet) {
if( edgeCost == 10 ) {
topoGraph[srcVertex][dstVertex] = 1; <<<<<---------- The point of crash
}
else if( edgeCost == 100000 )//restricted link {
topoGraph[srcVertex][dstVertex] = edgeCost;

[code]....

It seems like there is an undefined behaviour at the specified point of crash since it crashes with different values of srcVertex and dstVertex each time I run it.

What might be the reason for this crash ?

View 4 Replies View Related

C# :: One Thread Trying To Pass Data To Another Thread Using Serial Port

Jul 30, 2014

I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.

But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.

What can caused that, and How I can make it works?

SerialPortComm.cs

public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;

[Code] ....

View 7 Replies View Related

Visual C++ :: Add To Listbox Thread

Feb 15, 2015

Startthread get called to launch to update list box.

a)is it the only way to pass string to the PostMessage?. my concern is that allocate using new in each iteration each time slows it down a bit.

b)does OnAddToListBox look memory leak free?.

c)What is the best way handle m_pThread at the end?. Any way to improve it?.

Code:
UINT CMyDlg::Dump(LPVOID lparam) {
HWND *pHndl = static_cast<HWND *>(lparam);
char buffer[200];
for (int i = 0; i < 100; i++) {
sprintf_s(buf,"user %d, data %s",i, "Connected");

[Code] ....

View 8 Replies View Related

Visual C++ :: How To Check Thread With MFC

Feb 12, 2013

I use MFC Find console window and send key to console like this.

Code:
HWND w;
w = FindWindow(NULL, L"c:userspkrudocumentsvisual studio 2010ProjectsCleanVirusDebugCleanVirus.exe");

[Code]....

After program process success in console it not close console windows but it show like this in Output

The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).

I think if I can check when VC will show this line, then I can use FreeConsole(); for close console windows.

View 3 Replies View Related

Visual C++ :: Exit Application Using Thread In MFC SDI

Feb 4, 2014

I have a SDI application. I created a method OnClose to handle ON_WM_CLOSE of CMainFrm. This onclose() function calls a method in cmyview.cpp. Here, I created a thread that calls global function and from this function it calls another function in cmyview.cpp. At certain condition my application should close at here, I used postmessgae(WM_CLOSE (or) WM_DESTROY). I am having an error as object reference not set on postmessage(WM_CLOSE) it is going to afxwin2.inl page where exception occurs.

Below is code snippetHere, either j or k will only be true depneds on user input)

MainFrm.cpp:
void CMainFrame::OnClose()
{
CMyView* pview = (CMyView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
pview->method1();
}

[Code]...

View 3 Replies View Related

Visual C++ :: Using One Thread At A Time With CSemaphore

Oct 6, 2014

I need using CSemaphore class in MFC C++ application. I have an edit1 box with multil ine and each line has a string. I'm trying to loop through edit1 box and for each string to start a thread that is using the string for specific function. I'm trying to limit the run of only one thread at the same time with semaphores but all treads start at the same time.

So when i click button1 i loop through edit1 box and start threads:

Code:
void CMFCApplication1Dlg::onButton1Click() {
int i, nLineCount = edit1.GetLineCount();
CString strText, strLine, mesaj;
for (i = 0; i < nLineCount; i++) {

[Code] ....

While looping through edit1 box multi line and starting the threads:

Code:
UINT CMFCApplication1Dlg::StartThread(LPVOID param) {
WaitForSingleObject(semafor, INFINITE); // wait for semafor to signal
THREADSTRUCT* ts = (THREADSTRUCT*)param;
// here i'm doing some operations with the string from edit1 box
ReleaseSemaphore(semafor, 1, NULL); //release the semaphore for next thread to begin
}

Instead of running only one thread at a time all threads start. What am i doing wrong ?

View 14 Replies View Related

Visual C++ :: How To Fork Or Create Thread

Dec 23, 2012

How can I implement the paradigm demonstrated by the code below to run on WinXP?

I want to fork a process or create a thread that shares global variables with the parent process/thread.

The child process/thread monitors the progress of the parent process/thread.

I cannot find documentation for a fork function per se, a Unix term. It might be called something different for WinXP.

I would be happy to use threads instead. But I'm rusty even with Unix application threads; and I know nothing of WinXP application threads.

So any turnkey implementation that demonstrates the simplest use of process or thread functions for my purpose demonstrated below.

In either case, do "forked" processes and threads share global address space in WinXP, as they do in Unix?

I would prefer to avoid the overhead of IPC mechanisms. The "overhead" includes my own relearning curve.

The GUI screwed up my indentation. I would try to correct it. But the proper indentation appears when I edit the posting. I suppose I need to insert real tabs. Haven't figured out how (yet).

Not even real tabs work; and I cannot get the "paste as text" button to behave as I expect. What is the trick for posting indented text in this GUI?

#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
long curCount;
int isRunning;
int _tmain(int argc, char* argv[]) {
curCount = 0;
isRunning = 1;

[code]....

View 4 Replies View Related

Visual C++ :: Unable To Display Dialog In UI Thread

Mar 11, 2015

I am having a strange problem trying to display a dialog from a UI thread. The dialog simply fails to display. I have a function DisplayFlashBox(), which creates the UI thread:

CUIThread* CIMUIHelper:: DisplayFlashBox(const CString &sMessage, const int nInstrumentUID) {
CUIThread *pThread = new CUIThread();
pThread->SetString(sMessage);
pThread->SetInstrumentUID(nInstrumentUID);
pThread->CreateThread();

[Code] .....

The dialog doesn't display. When I tried debugging, I found the OnInitDialog() method of CIMFlashBox class doesn't actually return. Very strange. I tried calling the DoModal() method instead of Create, but doesn't display the dialog either.

View 5 Replies View Related

Visual C++ :: Calling Self-contained Posix Thread?

Mar 2, 2015

pThread turns out to be NULL here. Wondering what the correct way is...

Code:
class CPF_Thread {
public:
unsigned int threadID;
Coordinater coordinater;
virtual UINT proc() {

[Code] .....

View 2 Replies View Related

Visual C++ :: Unable To Invoke JScript Functions From Another Thread

May 6, 2013

I have main thread that creates an WebBrowser2 COM object. and i want to invoke JScript functions on it from another thread. i try to use GIT but still doesn't work for me.. there is a problem with marshal WebBrowser2 for JScript?

View 4 Replies View Related

Visual C++ :: Local Variable Be Passed As Parameter Into A New Thread?

Apr 1, 2013

Can local variable be passed as the parameter for a new created thread procedure? Here is the example code:

Code:
void CDLG::some_function()
{
CString strFileName="abc.doc";
//local variable, can it be valid for being passed into the following new thread???
//Can strFileName still be accessed from within the stack of thread procedure?
::AfxBeginThread(ProcessContentThread,(LPVOID)&strFileName);
}

[Code]...

There is another method using variable on the heap,

Code:

void CDLG::some_function()
{
CString strFileName="abc.doc";
CString* pstrFN=new CString(strFileName);
::AfxBeginThread(ProcessContentThread,(LPVOID)pstrFN);
}

[Code]...

I test these code, both methods work as expected, but I doubt whether the first method is a good way. OR if only the second method is the correct way to pass a parameter to a thread.

View 12 Replies View Related

Visual C++ :: Terminate A Thread When User Push Stop Button

Nov 16, 2012

I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.

I thought about creating a bool and checking its value periodically in the thread and when I push the stop button I change the value of the bool for that the thread breaks out of the loop and finishes.

View 5 Replies View Related

Visual C++ :: Obtaining Actual Effective Execution Time Per Thread With Hyperthreading

Jun 13, 2013

I'm looking for a function like GetThreadTimes, but one that gives correct results in a hyperthreading CPU.

For instance, if you start 2 threads on a CPU with 1 physical core and 2 logical cores, GetThreadTimes will say that both these threads use 100% CPU.

However, in reality they only use 50% each. Is there a function that returns correct results, or is there another workaround?

View 8 Replies View Related

Visual C++ :: How To Raise Priority Of MIDI Input Callbacks - Thread Pools

Sep 23, 2014

I'm the author of a realtime MIDI software called ChordEase which makes use of the MIDI aspects of the multimedia API, specifically MIDI input callbacks. In XP and before, these callbacks originated in the kernel and therefore had realtime priority by definition, but from Vista on, they originate in thread pool threads, and have a priority of zero. This is a problem because at priority zero they can be blocked by the GUI thread, causing serious latency, and I have proved that such blocking occurs.

I have experimented with raising the callback thread priority, using either of the following methods: 1) calling SetThreadPriority within the MIDI input callback function, and then setting a flag so that it isn't done repeatedly, or 2) creating a DLL that catches thread creation via DLL_ATTACH_THREAD in DllMain, and calling SetThreadPriority there. The first method is slightly wasteful since the flag has to be tested for every MIDI input event, but it also has the advantage of only affecting the MIDI input threads, whereas the second method affects all threads in the pool regardless of what they're used for. Neither method appears to cause any harmful effects but they make me nervous*. Other possible methods would include 3) using the thread pool API to raise the priority of the pool (assuming I could gain access to the pool handle somehow), or 4) permanently lowering the priority of the GUI thread, which I'm very reluctant to do because of the risk of unintended consequences.

I'm assuming the MIDI input callbacks are using threads in the default thread pool though I haven't actually proved this. Assuming that's so, are these threads private to my application, or is my application sharing them with other applications? Is there a safer way to achieve the result of increasing the priority of MIDI input callbacks? It's incredibly frustrating that MS would change the behavior of MIDI input callbacks so drastically without even telling anyone, but that's how it goes!

[URL] ....

*See for example theses warnings about changing thread pool priorities : [URL] ....

View 13 Replies View Related

C :: 16bit Samples Stored In Shorts - How To Reduce Bits

Dec 8, 2013

16bit samples stored in shorts how i can reduce bits ? i meann idea not sources. i try learn code itself (i not school but i still dont want premade solutions for this)... i mean way make 16bit sample sound for example 4bit/8bit... and these are are audiosamples.

View 8 Replies View Related

C :: Reduce Hexadecimal Numbers To One Byte Modulo 0x11b

Apr 21, 2014

When I'm trying to implement the AES (Advanced Encryption Standard) in C,

i need to reduce hexadecimal numbers to one byte, modulo 0x11b, but when I want to compute (0x57*0x13)%(0x11b) it returns 0xee instead 0xfe .

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved