|
I'm not familiar with CArray ( I use C++ containers ), but I don't see any problem with this. It would be easier to read your code if you checked 'Do not treat <'s as HTML tags' so it was all visiable though.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
lvantin wrote:
CArray m_pArr;
Correct Usage off CArray class is something like this, Ok let take example of your scenario only
Class CMyClass
{
CString m_szName;
CString m_szId;
long m_i4Age;
}
then you declare CArray something like this
CArray<CMyClass,CMyClass&> m_pArr;
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
It seems okay to me. Did you use a profiler to measure, or are you using Task Manager? If it is the latter, there is a good probability that the C++ Runtime Environment is not releasing the memory immediately to the OS. That is perfectly OK.
BTW, you don't really need to check if p is not NULL before deleting it, delete(p) itself handles the case where p is NULL. And setting p to NULL has no effect too.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
lvantin wrote:
2. In release mode, leak!!! memory is allocates for application never
decrease...
How are you confirming this?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I used Performance monitor, a tool is supported by Windows, to investigate this. Private Bytes of the application always increases when i used that code to allocate memory and never descreases when release it.
|
|
|
|
|
lvantin wrote:
Private Bytes of the application always increases when i used that code to allocate memory and never descreases when release it.
Which is perfectly normal.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hey all,
I'd like to start by saying that I am an electrical engineering student and have therefore had very little experience with Visual C++. However, a part of my senior design project requires a simple rs232 interface in visual c++. My design partner and I have designed the hardware and software needed to implement a traction control system for an R/C car. The traction system works fine, but the other part of our project is wireless transmission of the traction status and speed of the 4 wheels of the car to a laptop the user will have with them. The wireless hardware has been designed and built and is sending the traction status and wheel speed measurements formatted in bytes in the following manner:
0h10, traction status, 0h20, front left wheel speed, 0h30, front right wheel speed, 0h40, rear left wheel speed, 0h50, rear right wheel speed, and then back to 0h10, ...
(where the wheels speeds are also just byte values)
I pieced together what I could find online to write a simple windows program that would display this data using the 0h10, 0h20, ..., .. qualifiers to indicate what the next byte value received will represent (right front, left, etc).
In the program I assume that I read 1 byte at a time from the serial buffer and immediately process it before the next byte arrives which should be very possible since we are using a baud rate of only 2400 bps. I simply set a flag using the qualifiers to indicate what the next byte of data will represent. This method seems like it should work, but Im not sure if I am actually reading 1 byte from the serial buffer corrently or not.
The program compiles and initially displays the current vehicle wheel speeds and traction status but then fails to update these values at a usable rate. If after the program starts any wheel speed changes, the program doesn't register the change in incoming serial data for nearly a minute and a half. I tested the incoming serial data using a regular terminal program and the serial data changes instantly in response to vehicle wheel speed changes. Its as if the data on the screen is updated at a very slow rate and windows just stores all the incoming serial data until it finishes displaying what arrived earlier. I noticed using the windows task manager that the program continues to use more memory the entire time it is running which would reinforce my hypothesis that it is storing the incoming serial data, or there could be just a memory leak I am unaware of. I believe the cause of this to be related to the way I am reading the serial buffer using Cserial. Although like I said earlier, I dont have much experience with visual c++.
I have pasted below the code I am currently using. I know some of you are experts in visual c++ that can give me a simple explanation and/or fix to my problem. I am very close, as like I said, the serial data is read and displayed correctly when the program starts, it just fails to update using the incoming data at anything other than minute or two intervals which makes no sense to me.
Thanks for any and all suggestions.
Jordan
---------------------
Visual C++ Code
---------------------
#include <string>
#include <cstring>
#include <stdlib.h>
#include <afx.h>
#include "SerialWnd.h"
#include "Resource.h"
using namespace std;
HDC hdc ;
DCB dcb;
HANDLE hCom;
char buff[2];
char buffout[2];
HDC MemDCExercising;
PAINTSTRUCT Ps;
HBITMAP bmpExercising;
HINSTANCE hInst;
BOOL fSuccess;
unsigned long dwBytesRead = 0;
BYTE abBuffer[100];
char *pcCommPort = "COM1";
DWORD dwCommEvent;
DWORD dwMask;
DWORD inqueue;
DWORD outqueue;
int TractionData=0;
int WLF=0;
int WLR=0;
int WRF=0;
int WRR=0;
char fleft[26] = "Front Left Wheel Speed: ";
char fright[27] = "Front Right Wheel Speed: ";
char rleft[25] = "Rear Left Wheel Speed: ";
char rright[26] = "Rear Right Wheel Speed: ";
char tstatus[19] = "Traction Status: ";
CSerialWnd serial;
LRESULT CALLBACK Handler(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
if (iMsg == WM_PAINT)
{
hdc = BeginPaint(hWnd, &Ps);
// Load the bitmap from the resource
bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
// Create a memory device compatible with the above DC variable
MemDCExercising = CreateCompatibleDC(hdc);
// Select the new bitmap
SelectObject(MemDCExercising, bmpExercising);
// Copy the bits from the memory DC into the current dc
BitBlt(hdc, 0, 0, 782, 522, MemDCExercising, 0, 0, SRCCOPY);
// Restore the old bitmap
DeleteDC(MemDCExercising);
DeleteObject(bmpExercising);
EndPaint(hWnd, &Ps);
hdc = GetDC(hWnd);
SetTextColor(hdc, RGB(0,0,0));
//SetBkColor(hdc, RGB(0,0,0));
TextOut(hdc,385,435,fleft,26);
TextOut(hdc,5,175,fright,27);
TextOut(hdc,600,350,rleft,25);
TextOut(hdc,190,100,rright,26);
TextOut(hdc,330,30,tstatus,19);
}
if (iMsg == CSerialWnd::mg_nDefaultComMsg)
{
// A serial message occurred
const CSerialWnd::EEvent eEvent = CSerialWnd::EEvent(LOWORD(wParam));
const CSerialWnd::EError eError = CSerialWnd::EError(HIWORD(wParam));
switch (eEvent)
{
case CSerialWnd::EEventRecv:
hdc = GetDC(hWnd);
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(0,0,0));
serial.Read(abBuffer,1,&dwBytesRead,0,INFINITE);
sprintf(buffout,"%X",(LPCTSTR)abBuffer[0]);
SetTextColor(hdc, RGB(255,255,255));
//TextOut(hdc,0,80,buffout,2);
// Sets flags based on qualifiers
if ((buffout[0] == '1') && (buffout[1] == '0')) {
TractionData = 1;
break;
}
if ((buffout[0] == '2') && (buffout[1] == '0')) {
WLF = 1;
break;
}
if ((buffout[0] == '3') && (buffout[1] == '0')) {
WLR = 1;
break;
}
if ((buffout[0] == '4') && (buffout[1] == '0')) {
WRF = 1;
break;
}
if ((buffout[0] == '5') && (buffout[1] == '0')) {
WRR = 1;
break;
}
// Displays data based on flags
if (TractionData == 1) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc,434,30,buffout,1);
TractionData = 0;
break;
}
if (WLF == 1) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc,547,435,buffout,2);
WLF = 0;
break;
}
if (WLR == 1) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc,756,350,buffout,2);
WLR = 0;
break;
}
if (WRF == 1) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc,177,175,buffout,2);
WRF = 0;
break;
}
if (WRR == 1) {
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc,360,100,buffout,2);
WRR = 0;
break;
}
break;
}
return 0;
}
if (iMsg == WM_DESTROY) {
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow){
//Declare variables
const char* szAppName = "MyWin";
WNDCLASSEX wndclass;
HWND hWnd;
MSG msg;
hInst = hInstance;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = Handler;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
hWnd = CreateWindow(szAppName, "Wireless Telemetry Monitor", WS_OVERLAPPEDWINDOW,0,0, 782, 522, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
serial.Open(pcCommPort, hWnd, WM_NULL, 0, inqueue, outqueue);
serial.Setup(CSerial::EBaud2400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
serial.SetupHandshaking(CSerial::EHandshakeOff);
serial.SetMask(CSerial::EEventRecv);
serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);
while (GetMessage(&msg, NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
|
|
|
|
|
Hi, Is there anyone who knows how to enumerate all the available domains on a network. I want to list them down on a combo box. (Same as Windows login). Thanks. Ü
SDE
|
|
|
|
|
There's a program inside Programming Windows called Blowup
hdc = GetDC (hwnd) ;
hdcMem = CreateCompatibleDC (hdc) ;
hBitmap = CreateCompatibleBitmap (hdc,
abs (ptEnd.x - ptBeg.x),
abs (ptEnd.y - ptBeg.y)) ;
SelectObject (hdcMem, hBitmap) ;
StretchBlt (hdcMem, 0, 0, abs (ptEnd.x - ptBeg.x),
abs (ptEnd.y - ptBeg.y),
hdc, ptBeg.x, ptBeg.y, ptEnd.x - ptBeg.x,
ptEnd.y - ptBeg.y, SRCCOPY) ;
Before entering this snippet the mouse was captured by SetCapture(), ptBegin and ptEnd are the points when the left button was clicked and released, So after a click and release a rectangle was produced, ptBegin lies in the upper-left corner and ptEnd is at right-bottom. "hdc" is the program's window handle
I know even part of this rectangle lies out side of program's window(drag cursor out of the client area), the region created by ptBegin and ptEnd still valid (SetCapture()), but what makes me wonder is how's the image outside the program's client area can be used as a source HDC to be copied to hdcMem.
|
|
|
|
|
I created a dialog box with 3 controls using the ClassWizard. I created a variable for each control with type CComboBox. Within my constructor I set up the values associated with each index item:
m_combo1.SetItemData(0, 1);
m_combo1.SetItemData(1, 2);
m_combo1.SetItemData(2, 5);
When I run the program, it throws a debug assertion failed error. What seems to be the problem? Does it have something to do with its declaration? Thanks!
|
|
|
|
|
If you debug when you get the assert, you'll see the MFC source code where it's blowing up, and the comment above the ASSERT will answer your question.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Or u can do ur codings in OnInitDialog()
Zxczc
|
|
|
|
|
|
you can also use SetwindowText() to fill you controls with some datas.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
Currently I am developing a simple Dialog Based MFC application. The application connects to a server using the RakNet networking library. I am stuck because the networking library requires that each frame the application needs to check if a new packet has been recieved from the server. Does anyone know a way to call a function everyframe? I know that threads are a posibility, but I was hoping for something simpler.
|
|
|
|
|
Wow - is ALL that text your homework, or did you include some code you'd written ? We don't do homework here, and there's just too much there for anyone to wade through to work out if you've actually tried anything yourself, or if you're just looking for a free ride.
From what I read, it looks like you've got more than enough to go on with there.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
under neat of that problem is alls of my file that i did but some how won't run and error, and some function i did may not right
sorry i was wodering you
|
|
|
|
|
Nice... And what's the question ???
Honnestly, do you really think that we will read all of this ?? Do you really think that people here have nothing to do of their days? If you have clear questions, do ask but do not post your homework here, people won't do that for you.
And also, format your message a little bit cleaner instead of making a copy/paste of your homework.
|
|
|
|
|
|
I need to create a Emessaging cliet that will have a little text menu that will show the messages
check messages
and do anumber of tasks that are in this .h file
if you can help me out by creating the menu that would be awessome
~Thx
W00t
|
|
|
|
|
What messages?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
Hi there,
probably really easy this.
I have a combobox which works fine. I can select the line I want from the pull down menu, and when I use
comm_port = m_DropList.GetCurSel();
in my code, I get back the correct index. HOWEVER, I also want to be able to type in the selection (0 to 255) in the combobox, and have it recognise my selection in code, yet if I edit the box, the above line always returns -1. What else do I need to do to get the code to pick up that the selection has changed and to treat it as a valid selection. My combobox is configured as type Dropdown, so I assumed this would work quite straight forwardly.
Cheers
Dave C
|
|
|
|
|
I assume you added numbers 0 through 255 via AddString() (or InsertString() ). Yes? If that is the case, use GetWindowText() to get the text displayed in the combobox.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|