|
I really need some example and guide about how to program a sending data under mewtocol command messasge using TCP/IP. Can someone help me.
|
|
|
|
|
Does anyone know how to get the private memory usage of my program (e.g. "Private Bytes" in the Performance tool).
Thanks!
|
|
|
|
|
Find your 'process' by name, and then under items to add select the Private Bytes to the graph.
|
|
|
|
|
Sorry, should've been more specific. I want to be able to do that from within my program. I hunted around the various APIs, but I couldn't find anything.
|
|
|
|
|
|
Create an instance of CMemChecker.
Call CMemChecker.ScanMemory();
Examine CMemChecker.m_BytesPrivate
It will be as close or more accurate than the other tool.
If you want how much is used by the DLL and other executable images, then look at
CMemChecker.m_BytesImage
If you want to know how much 'memory' is being used, then look at
CMemChecker.m_BytesCommit
If you want to know how much of your virtual address space has been consumed, then look at total of CMemChecker.m_BytesCommit + CMemChecker.m_BytesReserved
<br />
<br />
<br />
#pragma once<br />
<br />
class CMemChecker<br />
{<br />
public:<br />
<br />
CMemChecker();<br />
virtual ~CMemChecker();<br />
<br />
BOOL ScanMemory(void);<br />
<br />
virtual void ResetData(void);<br />
<br />
<br />
DWORD m_BytesCommit;<br />
DWORD m_RegionCountCommit;<br />
<br />
DWORD m_BytesFree;<br />
DWORD m_RegionCountFree;<br />
<br />
DWORD m_BytesReserved;<br />
DWORD m_RegionCountReserved;<br />
<br />
<br />
DWORD m_BytesImage;<br />
DWORD m_RegionCountImage;<br />
<br />
DWORD m_BytesMapped;<br />
DWORD m_RegionCountMapped;<br />
<br />
DWORD m_BytesPrivate;<br />
DWORD m_RegionCountPrivate;<br />
<br />
<br />
DWORD m_BytesOrphaned;<br />
DWORD m_RegionCountOrphaned;<br />
<br />
DWORD m_BytesAvailable;<br />
DWORD m_RegionCountAvailable;<br />
<br />
DWORD m_RegionCountTotal;<br />
<br />
DWORD m_MaxFreeBlock;<br />
DWORD m_MinFreeBlock;<br />
<br />
protected:<br />
<br />
SYSTEM_INFO m_SystemInfo;<br />
<br />
virtual void AccumulateData (PMEMORY_BASIC_INFORMATION lpMemInfo);<br />
virtual bool IsRegionOrphaned(PMEMORY_BASIC_INFORMATION lpMemInfo) const;<br />
<br />
};<br />
<br />
<br />
<br />
<br />
#include "stdafx.h"<br />
#include "limits.h"<br />
#include "CMemChecker.h"<br />
<br />
CMemChecker::CMemChecker()<br />
{<br />
ResetData();<br />
}<br />
<br />
CMemChecker::~CMemChecker()<br />
{<br />
}<br />
<br />
<br />
void CMemChecker::ResetData(void)<br />
{<br />
::GetSystemInfo(&m_SystemInfo);<br />
<br />
m_RegionCountTotal = 0;<br />
<br />
m_BytesCommit = 0;<br />
m_RegionCountCommit = 0;<br />
<br />
m_BytesFree = 0;<br />
m_RegionCountFree = 0;<br />
<br />
m_BytesReserved = 0;<br />
m_RegionCountReserved = 0;<br />
<br />
m_BytesImage = 0;<br />
m_RegionCountImage = 0;<br />
<br />
m_BytesMapped = 0;<br />
m_RegionCountMapped = 0;<br />
<br />
m_BytesPrivate = 0;<br />
m_RegionCountPrivate = 0;<br />
<br />
m_BytesOrphaned = 0;<br />
m_RegionCountOrphaned = 0;<br />
<br />
m_BytesAvailable = 0;<br />
m_RegionCountAvailable = 0;<br />
<br />
m_MaxFreeBlock = 0;<br />
m_MinFreeBlock = ULONG_MAX;<br />
}<br />
<br />
<br />
BOOL CMemChecker::ScanMemory(void)<br />
{<br />
BOOL bSuccess = TRUE;<br />
SIZE_T BytesRead;<br />
<br />
MEMORY_BASIC_INFORMATION TheBuffer;<br />
<br />
ResetData();<br />
<br />
LPVOID lpAddress = (LPVOID)m_SystemInfo.lpMinimumApplicationAddress;<br />
<br />
while( lpAddress < m_SystemInfo.lpMaximumApplicationAddress ){<br />
<br />
BytesRead = ::VirtualQuery(lpAddress, &TheBuffer, sizeof(TheBuffer));<br />
<br />
if( BytesRead < sizeof(TheBuffer) ){<br />
break;<br />
} else {<br />
AccumulateData(&TheBuffer);<br />
lpAddress = (LPVOID)((DWORD)TheBuffer.BaseAddress + (DWORD)TheBuffer.RegionSize);<br />
}<br />
}<br />
<br />
return bSuccess;<br />
}<br />
<br />
<br />
void CMemChecker::AccumulateData(<br />
PMEMORY_BASIC_INFORMATION lpMemInfo<br />
){<br />
m_RegionCountTotal++;<br />
<br />
switch( lpMemInfo->State ){<br />
<br />
case MEM_COMMIT:<br />
m_BytesCommit += lpMemInfo->RegionSize;<br />
m_RegionCountCommit++;<br />
break;<br />
<br />
case MEM_FREE:<br />
m_BytesFree += lpMemInfo->RegionSize;<br />
m_RegionCountFree++;<br />
<br />
if( m_MaxFreeBlock < lpMemInfo->RegionSize ){<br />
m_MaxFreeBlock = lpMemInfo->RegionSize;<br />
}<br />
<br />
if( m_MinFreeBlock > lpMemInfo->RegionSize ){<br />
m_MinFreeBlock = lpMemInfo->RegionSize;<br />
}<br />
<br />
if( IsRegionOrphaned(lpMemInfo) ){<br />
<br />
m_BytesOrphaned += lpMemInfo->RegionSize;<br />
m_RegionCountOrphaned++;<br />
<br />
} else {<br />
<br />
m_BytesAvailable += lpMemInfo->RegionSize;<br />
m_RegionCountAvailable++;<br />
}<br />
<br />
break;<br />
<br />
case MEM_RESERVE:<br />
m_BytesReserved += lpMemInfo->RegionSize;<br />
m_RegionCountReserved++;<br />
break;<br />
<br />
}<br />
<br />
switch( lpMemInfo->Type ){<br />
<br />
case MEM_IMAGE:<br />
m_BytesImage += lpMemInfo->RegionSize;<br />
m_RegionCountImage++;<br />
break;<br />
<br />
case MEM_MAPPED:<br />
m_BytesMapped += lpMemInfo->RegionSize;<br />
m_RegionCountMapped++;<br />
break;<br />
<br />
case MEM_PRIVATE:<br />
m_BytesPrivate += lpMemInfo->RegionSize;<br />
m_RegionCountPrivate++;<br />
break;<br />
<br />
}<br />
}<br />
<br />
bool CMemChecker::IsRegionOrphaned(<br />
PMEMORY_BASIC_INFORMATION lpMemInfo<br />
) const {<br />
return false;<br />
}<br />
<br />
<br />
<br />
|
|
|
|
|
I have a mewtocol command message format which have header(%or<),unit no. of destination,command code(#), command name (e.g.read contact), target that reads the value, check code(BCC), and terminator(Cr). I want to ask that when I send a data, it will send the header, unit of destination, command code and etc or it will send whole format to the receiver? I need to write a program that can send the data like what I have mention above. Can someone give some example or guide how to write the program. I only have a program that can send message just like msn. I don't have any idea how to send data like I mention above. Can help me......
|
|
|
|
|
jyhguang wrote:
I need to write a program that can send the data like what I have mention above
It would help if someone (here) understood what you mentioned above.
Before a receiver can know what it's expected to receive, it has to be told what to expect (or request the data itself). I assume that the destination command code(#) indicates the data type expected. In that case you should already have what you need.
Just wondering, how many peaple here did you expect to know about: mewtocal OPC servers and PLCs?
INTP
Every thing is relative...
|
|
|
|
|
I have a MFC Application with ToolBars etc.
I want to create a Modeless Dialog Box, but I do not the user to be able to click any buttons in the Main Application while this Dlg Box is displayed. Is there a way to do this, or do I have to use a Modal Dlg Box. The problem is if I have to use a Modal Dlg Box then I will have to spawn a separate thread to do this as I have to do some background processing.
Thanks for your help.
|
|
|
|
|
You basically want a modal dialog box, so why not create one ? I don't see how being modal or modeless changes the need for a background thread, assuming you need one at all.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So disable the main application window before you show the dialog.
A bit of advice - it sounds like you're trying to do some sort of progress / wait dialog. That's fine - this is a good way to go about that. But keep in mind, if you're doing some sort of lengthy processing in your primary (UI) thread, the interface won't respond or repaint while that's happening anyway, since messages won't get pumped.
If you have something that is gonna take a while, see if you can't just spin off a separate thread to handle it, posting back status messages or whatever to the main thread. Trust me, it's a lot easier to plan it out and do it right the first time than it is to go back and hack around laziness later...
|
|
|
|
|
I am debugging a Visual C++ program, and my job is to speed up the file access. Currently the program is reading in a 600 MB ascii-text file using fopen and fscanf, etc., in text mode. Is there an easy way to speed this up? I have tried using streams and they aren't defined. Would changing it to binary make it faster?
Thanks so much for your help!
Jennifer
|
|
|
|
|
JenniferLeonard522 wrote:
I have tried using streams and they aren't defined.
How do you mean, they aren't defined ? Regardless of speed issues, moving your file handling code to c++ is a positive step.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
When I use ifstream and cin they aren't defined. the code I am debugging currently uses fopen, fscanf, fprintf, etc.
Thanks!
Jen
|
|
|
|
|
Anonymous wrote:
When I use ifstream and cin they aren't defined.
Did you include them ? ifstream is in fstrem and cin is in iostream. You need to scope them in std, or pull them into the global namespace with using statements as well.
Anonymous wrote:
the code I am debugging currently uses fopen, fscanf, fprintf, etc.
Yeah, the world is full of crappy code that uses those instead of C++. It's a common problem.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
For reading files of this size, I don't recommend using C++ stream classes.
Instead, I recommend you use file mapping API functions, which will greatly increase the speed of your code.
For more info, look at your help files for the following API functions:
MapViewOfFile
CreateFileMapping
UnmapViewOfFile
For example code, check out the following links:
http://code.axter.com/MapFileToMemory.h
and
http://code.axter.com/mapfile2mem.cpp
The C++ stream classes are reliable, but not very speedy.
If you have a large file, and you need speed, they're not the best choice.
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
Hello.
One way to speed up file handling (while maintaining ths stream I/O) could be to use fread() and fwrite(), using a buffer size that match the disk sector size of the file. Since the normal sector size is 512 bytes, read and write blocks that is an even multiplier of 512.
(I guess the most effective disk I/O would be to read/write the size of a complete disk cluster at once, but I'm not sure).
This means that you have to use your own code to extract/create the data (text lines) in the buffer, but that job has to take place anyhow. If it´s done in the runtime library or in your own code dosen't really matter (provided that your own code is efficially written).
Another way could be to use the native Win32-API and to use overlapped I/O. But it works (logically) in the same way as fread/fwrite, which means you still have to write your own code to handle your buffer.
|
|
|
|
|
I rated your answer as 5 (but I do not know if it took).
You are correct about reading and writing a cluster at a time (or a multiple there of). The problems may start to appear with how the memory required is managed, which the question ignores (I,m not going into that).
The simpilest solution (if they are using MFC), is to use a CMemFile (which side steps the issue entirely and allows MFC to handle it).
INTP
Every thing is relative...
|
|
|
|
|
Thank you for all the suggestions. I looked into CMemFile, but it said "
Because CMemFile doesn't use a disk file, the data member CFile::m_hFile is not used and has no meaning." I read through the description and didn't see how to use it to read a large data file from disk.
I also looked into writing the file a cluster at a time, but the problem is that my file is constantly growing (every 10 minutes it gets more information). So right now it is 600MB, but in a couple months it will be 800MB. What would the quickest way be to read a large file like this?
Thanks!
Jen
|
|
|
|
|
The first statement that the m_hFile is not used and has no meaning is essentially true. That is the file handle was only needed long enough to load the file into memory. I (incorrectly) assumed that was not the case (blast it).
The fasted way to read a file is a cluster at a time. You do not need to actualy care about this detail, since you are only reading the file as a whole.
Look into sharing file read access. This will not speed up the actual read time, but will reduce the preceived time (if used properly). What this means, is that (if) the file is only changed by adding to it, then you just need to read the additional information added to the file.
What I mensioned above is also true if you do not have file sharing read access. What I mean is that (assuming the other application closes the file, after writing to it) you can check if the file size has changed on a regular basis, and just read the changes.
What all that bull boils down to is this: Only read what has changed and nothing more.
I hope that helps, because I cann't explane all the ideas that have poped into my head.
INTP
Every thing is relative...
|
|
|
|
|
I am doing a project that requires two monitors, one standard display and one 3D. The video card is cloning the display from one to another (not a dual monitor situation where the display is split).
This is fine but here's my problem:
I need to make one monitor sleep while the 3D monitor shows something 3D Upon the mouse movement, make the 3D monitor sleep while the other monitor is powered-up to show a form, then back to the 3D monitor when the form is submitted.
I have found this code:
// Turn off monitor
Sleep(500); // Eliminate user's interaction for 500 ms
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
// Turn on monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);
// Low power monitor
Sleep(500); // Eliminate user's interaction for 500 ms
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 1);
But I only need to make one of the monitors sleep at a time. Can this even be done?
|
|
|
|
|
Use dual View Mode on your video card to have to separate display, and then you can create Direct3D surface on the second monitor, and to sleep it...
NG
|
|
|
|
|
I am working in VC++ 6 under Windows NT/2000. I need to access the OS environment variables in code similar to the following in VB:
m_strAllUsersProfile = Environ("ALLUSERSPROFILE")
How do I do this?
Thanks...
|
|
|
|
|
How about getenv() ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I am missing something to get it to work; can you supply more info/working example with any headers, whatever? for instance, accessing ALLUSERSPROFILE or other?
thanks
|
|
|
|