|
jhwurmbach wrote: From your test-code I got 56msec vs. 85 msec for the map.
debug or release ?
jhwurmbach wrote: Thats factor 1.5
I'm still unimpressed.
if only my customers were so ambivalent about performance!
|
|
|
|
|
Chris Losinger wrote: debug or release
VC++ 7.1. Release mode.
There is so much security built in in Debug, that there is no point comparing with raw C.
Chris Losinger wrote: if only my customers were so ambivalent about performance!
They are for me. At least for the sub-second delays we are talking about here.
I have added the stdext::hash_map and now I get
map: 57 msec
hash_map: 24 msec
C-Array: 85 msec
Here is my code:
#include "stdafx.h"
#include "Windows.h"
#include "MMSystem.h"
#pragma comment( lib, "winmm")
#include <tchar.h>
#include <iostream>
#include <map>
#include <hash_map>
#undef max
#undef min
static const int TARGET_RESOLUTION = 1;
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::map<int, int> HistoMapT ;
typedef stdext::hash_map< int, int> HashHistoMapT;
typedef std::pair<int, int> Int_PairT;
const int w = 1000;
const int h = 1000;
TIMECAPS tc = {0};
UINT wTimerRes = 5;
if( ::timeGetDevCaps( &tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
{
std::cout << "Timer Error";
return system("pause");
}
wTimerRes = std::min( std::max( tc.wPeriodMin, (UINT)TARGET_RESOLUTION), tc.wPeriodMax);
::timeBeginPeriod( wTimerRes);
BYTE *p = new BYTE[w * h * 3];
for (int x=0; x< w;x++)
{
for (int y=0;y< h;y++)
{
p[x * 3 + y * w * 3 + 0] = w % 256;
p[x * 3 + y * w * 3 + 1] = h % 256;
p[x * 3 + y * w * 3 + 2] = (w + h) % 256;
}
}
const UINT before1 = ::timeGetTime();
{
BYTE * pix = p;
HistoMapT theMap;
for (int x=0;x< w;x++)
{
for (int y=0;y< h;y++)
{
const int color_number = RGB(pix[0], pix[1], pix[2]);
HistoMapT::iterator theIterator = theMap.find(color_number);
int value = 1;
if (theIterator != theMap.end() )
{
value += (*theIterator).second;
}
theMap.insert(Int_PairT(color_number, value));
pix+=3;
}
}
}
const UINT after1 = ::timeGetTime();
const UINT before2 = ::timeGetTime();
{
BYTE * pix = p;
HashHistoMapT theMap;
for (int x=0;x< w;x++)
{
for (int y=0;y< h;y++)
{
const int color_number = RGB(pix[0], pix[1], pix[2]);
HashHistoMapT::iterator theIterator = theMap.find(color_number);
int value = 1;
if (theIterator != theMap.end() )
{
value += (*theIterator).second;
}
theMap.insert(Int_PairT(color_number, value));
pix+=3;
}
}
}
const UINT after2 = ::timeGetTime();
const UINT before3 = ::timeGetTime();
{
BYTE * pix = p;
int *histo = new int[256 * 256 * 256];
memset(histo, 0, 256 * 256 * 256 * sizeof(histo[0]));
for (int x=0;x< w;x++)
{
for (int y=0;y< h;y++)
{
histo[RGB(pix[0], pix[1], pix[2])]++;
pix+=3;
}
}
delete [] histo;
}
const UINT after3 = ::timeGetTime();
delete [] p;
::timeEndPeriod( wTimerRes);
std::cout << "Elapsed timing map: " << (after1 - before1) << " msec." << std::endl;
std::cout << "Elapsed timing hash_map: " << (after2 - before2) << " msec." << std::endl;
std::cout << "Elapsed timing C-Code: " << (after3 - before3) << " msec." << std::endl;
return system("pause");
}
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
there was a bug in my original test code.
you need to change this:
p[x * 3 + y * w * 3 + 0] = w % 256;
p[x * 3 + y * w * 3 + 1] = h % 256;
p[x * 3 + y * w * 3 + 2] = (w + h) % 256;
(w and h are constant so the image is a solid color)
to this:
p[x * 3 + y * w * 3 + 0] = x % 256;
p[x * 3 + y * w * 3 + 1] = y % 256;
p[x * 3 + y * w * 3 + 2] = (x + y) % 256;
Elapsed timing map: 1002 msec.
Elapsed timing hash_map: 1887 msec.
Elapsed timing C-Code: 120 msec.
Press any key to continue . . .
|
|
|
|
|
Chris Losinger wrote: Elapsed timing map: 1002 msec.
Elapsed timing hash_map: 1887 msec.
Elapsed timing C-Code: 120 msec.
Press any key to continue . . .
Here, its
Elapsed timing map: 455 msec.
Elapsed timing hash_map: 247 msec
Elapsed timing C-Code: 185 msec.
Are you still in Debug?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: Are you still in Debug?
nope.
VS05, Release. optimized for "Maximize Speed"
|
|
|
|
|
Hi
When I right click on a folder , I need to disable any of the Menu Option.
Any Suggestions would be helpful.
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
even iam eager to find answer for this.
thanks to the poster and the answerer.
|
|
|
|
|
When you use the CMenu class, you can disable menu options as follows:
CMenu * Menu = GetMenu (); // Gets the window's menu (if any)
if (Menu != (CMenu *)NULL) // make sure there is a menu
{
CMenu * SubMenu = Menu->GetSubMenu (nItem); // Gets the submenu at nItem (starts at 0)
if (SubMenu != (CMenu *)NULL) // make sure there is a submenu
{
SubMenu->EnableMenuItem (nMenuItemID, MF_GRAYED|MF_BYCOMMAND); // disables the menuitem
}
}
The itemID can be either the command id or the position in the menu. This is indicated by the MF_BYCOMMAND, which can be replaced by MF_BYPOSITION to use a sequence number rather that the command ID.
In stead of MF_GRAYED (which disables the command and grayes it), you can also use MF_DISABLED (which disables the command but does not gray it) and of course MF_ENABLED, which enables the command.
Goof luck
William
|
|
|
|
|
Thanks william.
What I did is, Iam getting the Handle of Windows Media Player Application.
and from it a pointer to the menu bar.Now I want to disable the File->Open menu Item . How Should I do it?
Iam doing as below...
CWnd *pWnd = CWnd::FindWindow(_T("WMPlayerApp"),NULL);
CMenu *pMenu = pWnd->GetMenu();
if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
{
CMenu * pSubMenu = pMenu->GetSubMenu (0);
if (pSubMenu != (CMenu *)NULL)
{
pSubMenu->EnableMenuItem (nMenuItemID, MF_GRAYED|MF_BYCOMMAND);
}
}
What is that I should specify in place of nMenuItemID?
How do I know the Id of a sub menu in another Appln?
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
I got it...
pSubMenu->EnableMenuItem (pSubMenu->GetMenuItemID(0), MF_GRAYED|MF_BYCOMMAND); // disables the menuitem
Thanks.
Today is a gift, that's why it is called the present.
|
|
|
|
|
Hello again,
Now, I have problem upon building an MFC project.
Error is: "unexpected end of file while looking for precompiled header directive"
This is due to insertion of an API. I added these files and when I build the project the error appears. Does someone knew of the cause of this problem?
Do I need to change the build properties?
Hope somebody can comment.
Thanks.
|
|
|
|
|
Either you have to include the stdafx.h in the newly added file or you can change the setting so that, the file is not using the precompiled hearder file. for this follows the below step.
project setting->c++->In the categaory combo select "precompiled header". select your file in the left tree view and change the settings to "Not using precompiled headers".
|
|
|
|
|
Thank you very much nave for your time.
I have also figured it out.
Till next post. God Bless.
|
|
|
|
|
For example, Inside a Dialog i have 3 edit controls. If i want to update all 3 controls, i will call UpdateData(True). If, i want to update only a particular contol value(i.e. i don't want to update remaining 2 controls value). how is it possible?
Sethuraman.K
|
|
|
|
|
|
Sethuraman.K wrote: For example, Inside a Dialog i have 3 edit controls. If i want to update all 3 controls, i will call UpdateData(True). If, i want to update only a particular contol value(i.e. i don't want to update remaining 2 controls value). how is it possible?
Sethuraman.K
Use Control's SetWindowText api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thanks Alok & Naveen.
I Have another Method also. But I don't know is it correct method or not.
CButton *but = (Cbutton*) GetDlgItem(IDD_CNT1);
but->UpdateData(TRUE);
Sethuraman.K
|
|
|
|
|
|
hi sethuraman,
declare control varaible for each edit box in the classwizard member variable tab.
call that method updatedata(bool) for corresponding edit box variable. and up date to true. then u can acheive ur goal.
eg code:
m_ctrlEdtVar1.UpdateData(true);
here m_ctrlEdtVar1 is the control variable for edit box one.
i hope now u understood.
bye
|
|
|
|
|
hi,
this is the alternate way of implementing.it is some what better way becz you are getting dynamically.
GetDlgItem(ID_of_EditBox_control)->UpdateData(bool);
eg code :
GetDlgItem(IDC_EDIT1)->UpdateData(true);
bye
|
|
|
|
|
Sethuraman.K wrote: ...i will call UpdateData(True).
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am using SQL Server and VC++ 2005.
How to know programatically whether column type of a particular field is CHAR or VARCHAR using OLEDB or ODBC?
|
|
|
|
|
i believe that value you are retrieving from database in a "variant" variable
if so then you can differintiate using the variant type
types are:-
BSTR FAR* pbstrVal; // VT_BYREF|VT_BSTR. for varchar
char cVal; // VT_I1. for char
Regards,
Pankaj Sachdeva
"There is no future lies in any job"
"but"
"future lies in the person who holds the job"
|
|
|
|
|
With ODBC, you can use SQLColumns()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I'm writing some code to traverse an Xml document generated by XmlWriter. The document is extremely simple. It consists of a single element with a list of sub-elements storing some values as strings. I am having a problem using XmlReader to traverse the file to retrieve the results though.
I am running Visual Studio 2005 with .NET Framework 2.0.
Effectively what I want to do is to read each element, check a lookup table to see where to store the value associated with the element and move onto the next one. The problem is that I get a compile error when I attempt to use the EOF property.
<br />
int iRead;<br />
XmlReader ^xtr;<br />
xtr = XmlReader::Create(strFullPath);<br />
<br />
xtr->Read();<br />
<br />
while (!xtr->EOF)
{<br />
if ((xtr->NodeType == XmlNodeType::Element) && (xtr->Name == "AdminVal"))<br />
{<br />
iRead = xtr->ReadElementContentAsInt();
}<br />
else<br />
xtr->Read();
}<br />
Now the xtr->EOF does not work at all. It will not compile with it in place but if I replace it with a while(1) then it works 100% fine (except detecting the end of the list is a problem!). I know I can tell the end of the file state from the xtr->Read() return val but if the if statement is traversed, I do not get the opportunity to read the state.
The error listing is
error C2059: syntax error : '('
error C2143: syntax error : missing ';' before '{'
error C2039: 'xtr' : is not a member of 'System::Xml::XmlReader'
c:\windows\microsoft.net\framework\v2.0.50727\system.xml.dll : see declaration of 'System::Xml::XmlReader'
Is this a bug?
Thanks for any assistance!
|
|
|
|