|
Im having a problem with timing a function. Here's how Im doing it now:
<br />
const double LOOP_MAX = 999;<br />
LARGE_INTEGER tCS,tCE;<br />
double Ang = 0,Res;<br />
<br />
QueryPerformanceCounter(&tCS);<br />
<br />
while (Ang++ < LOOP_MAX)<br />
CMObj::Function(Ang, Res);<br />
<br />
QueryPerformanceCounter(&tCE);<br />
<br />
tCS.QuadPart = tCE.QuadPart- tCS.QuadPart;<br />
QueryPerformanceFrequency(&tCE);<br />
<br />
double t = (double)tCS.QuadPart / tCE.QuadPart;<br />
<br />
double ps = LOOP_MAX / t;<br />
When I run the LOOP_MAX at 1 - 999, I get about 393,000 calls per second. But as I raise LOOP_MAX from there my calls per second drop (At 99,999 I get only 85,022). Is there something wrong with the way Im calculating this, or is there a reason why my call time would drop?
|
|
|
|
|
Try something like this
I just found this code in my mail, I havent used this code, but my friend told me it just worked fine for him.
<br />
#include < iostream ><br />
#include < windows.h ><br />
<br />
int DoTest()<br />
{<br />
int i;<br />
i = 42;<br />
return i*15;<br />
}<br />
<br />
int DummyTest()<br />
{<br />
return 0;<br />
}<br />
<br />
int main()<br />
{<br />
__int64 i64Start;<br />
__int64 i64End;<br />
__int64 i64Overhead;<br />
__int64 i64Frequency;<br />
__int64 i64Elapsed;<br />
<br />
const int iIterations = 100000;<br />
int result;<br />
<br />
QueryPerformanceCounter((LARGE_INTEGER*)&i64Start);<br />
for (int i = 0; i < iIterations; ++i)<br />
result = DummyTest();<br />
QueryPerformanceCounter((LARGE_INTEGER*)&i64End);<br />
<br />
i64Overhead = i64End - i64Start;<br />
<br />
QueryPerformanceCounter((LARGE_INTEGER*)&i64Start);<br />
for (i = 0; i < iIterations; ++i)<br />
result = DoTest();<br />
QueryPerformanceCounter((LARGE_INTEGER*)&i64End);<br />
<br />
i64Elapsed = (i64End - i64Start) - i64Overhead;<br />
<br />
QueryPerformanceFrequency((LARGE_INTEGER*)&i64Frequency);<br />
<br />
std::cout << "Time elapsed was: " << (double)i64Elapsed /<br />
(double)i64Frequency << " seconds" << std::endl;<br />
<br />
return 0;<br />
}<br />
Cheers
Kannan
|
|
|
|
|
I need a non-MFC method for converting the contents of a FILETIME struct into an integer (or double) representation that can be used for date/time comparisons.
Anybody got anything like that?
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|
Well, I was gonna suggest CTime, but...
John Simmons / outlaw programmer wrote:
I need a non-MFC method
Actually, I think the only reason I even use MFC is for things like CTime and CString.
Anyway, take a look @ this[^] if you haven't already. It works with a SYSTEMTIME structure, but if you get the number of days or hours out of the 100-nanosecond intervals of the FILETIME, (like with an int64 or LONGLONG) you may be able to use some of the stuff in that article to add the time onto January 1, 1601 or whenever the FILETIME date thing starts (i didn't see any MFC stuff in there whilst quickly passing through)...
P.S. Sorry if that is of absolutly no help
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
From MSDN:
"Copy the resulting FILETIME structure to a ULARGE_INTEGER structure. Use normal 64-bit arithmetic on the ULARGE_INTEGER value."
Or you could convert it using FileTimeToSystemTime() and then populate the old struct tm.
J
May the bear never have cause to eat you.
|
|
|
|
|
Is the CompareFileTime() API insufficient for your needs? If you need a single number (not a struct) you can convert a FILETIME to a quadword:
FILETIME ft;
DWORDLONG qwTime;
qwTime = DWORDLONG(ft.dwHighDateTime) << 32 | ft.dwLowDateTime;
--Mike--
"Adventure. Excitement. A Jedi craves not these things."
-- Silent Bob
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Ok I've changed things around and it is as good as working apart from.....
1. If the queue has been emptied (after input) and I then try to view the queue I'd like a message no data in queue, have tried various methods to no avail, at the moment it just returns to main menu, as it runs void show and shows nothing as it should, but I want that message!!
2. My queue size isn't owrking i can have a queue of 3 and it will allow a 4th to be entered, yet NOT store this (GOOD), but would be better to not allow the 4th to be entered.
Thanks in advance.
Ian
2.
#include<iostream.h><br />
class Queue<br />
{<br />
private:<br />
int *input;<br />
int Array_Size;<br />
int first;
int last;
public:<br />
Queue(int);<br />
~Queue();<br />
void push(int);<br />
int pop();<br />
void show();<br />
};<br />
<br />
Queue::Queue(int data)<br />
{<br />
Array_Size=data + 1;<br />
input = new int[Array_Size];<br />
first=Array_Size;<br />
last=0;<br />
}<br />
<br />
Queue::~Queue()<br />
{<br />
delete input;
}<br />
void Queue::push(int info)<br />
{<br />
if ( first == last + 1 ) <br />
{<br />
cout<<"Queue is full\n";<br />
return;<br />
}<br />
<br />
input[last++] = info;
last %= Array_Size;
}<br />
int Queue::pop()<br />
{<br />
if ( first % Array_Size == last ) <br />
{<br />
cout<<"\n\nNo students waiting in the queue\n";<br />
return -1;<br />
}<br />
<br />
first %= Array_Size;
return input[first++];
}<br />
<br />
void Queue::show()<br />
{<br />
int it = first;<br />
while ( it != last )<br />
{<br />
it %= Array_Size;<br />
cout<<"|"; cout<<input[it++]; cout<<"| ";<br />
}<br />
<br />
}<br />
<br />
int menu()<br />
{<br />
int choice = 0;<br />
cout<<"\n\n\t\t**MAIN MENU**";<br />
cout<<"\n\n\t1\tStudent number to join the queue";<br />
cout<<"\n\t2\tStudent seen (Remove from queue)";<br />
cout<<"\n\t3\tView the students in the queue";<br />
cout<<"\n\t4\tEXIT";<br />
cout<<"\n\n\tPlease enter your choice : ";<br />
cin>>choice;<br />
return choice;<br />
}<br />
<br />
int main()<br />
{<br />
int StudentID = 0;
int qsize;<br />
int option;<br />
int set=0;<br />
<br />
cout<<"\n\tPlease enter the length of the Queue : ";<br />
cin>>qsize;<br />
set = qsize;<br />
while (qsize<1 ||qsize>15)<br />
{ <br />
cout<<"\nNot a valid queue size, must be between 1 and 15";<br />
cout<<"\nTry again: ";<br />
cin>>qsize;<br />
}<br />
Queue q(qsize);<br />
do<br />
{<br />
option = menu();<br />
switch(option)<br />
{<br />
case 1:<br />
cout<<"\n\t* * Valid student numbers between 1 and 500 only * *\n";<br />
cout<<"\nEnter the student number : ";<br />
cin>>StudentID;<br />
while (StudentID < 1 || StudentID > 500)<br />
{<br />
cout<<"Invalid entry try again: ";<br />
cin>>StudentID;<br />
}<br />
q.push(StudentID);<br />
cout<<"\nStudent "<<StudentID<<" has been inserted into queue.";<br />
break;<br />
case 2:<br />
<br />
if ( ( StudentID = q.pop() ) != -1 )<br />
cout<<"\nStudent "<<StudentID<<" has been deleted from the queue.";<br />
break;<br />
case 3:<br />
<br />
if (StudentID==0||StudentID==-1)<br />
{<br />
cout<<"\nNo students entered yet!";<br />
break;<br />
}<br />
<br />
q.show();<br />
break;<br />
case 4:<br />
cout<<"\n** GOODBYE **\n";<br />
break;<br />
default:
cout<<"\nIncorrect entry, try again with 1,2,3 or 4.";<br />
}<br />
}<br />
while (option!=4);<br />
}
|
|
|
|
|
Does your queue need to be a fixed size ? The other way to do it is a linked list, which is where you create a series of items that each contain the data you want, and a pointer to the next item, and possibly the previous also.
ian_ok wrote:
delete input; // Clean up
This does not work. To delete an array you need to do this:
delete [] input;
ian_ok wrote:
first=Array_Size;
last=0;
What are these for ? If you have an array, you can keep an index of how many items you have, and access items using either array notation ( input[pos] ), or pointer arithmetic ( *(input+pos) ).
I see you're using array notation.
ian_ok wrote:
first %= Array_Size; // Wrap the queue
return input[first++]; // Remove
I don't get this - how does this remove items from the queue ? That is, how does it reclaim the memory and make room in the queue ? If you want to use an array as your storage, you should use memcpy to move all the existing values down so there is room created at the end.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hi everyone!
I need to resize all the controls in a CFormView class on WM_SIZE message.
I tried to resize each control seperately but it didn't worked.
Also tried the code from OnInitialUpdate():
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
but it does not resizes the controls...
Any solutions of the problem?
Thanks in advance!
Gogou
|
|
|
|
|
Gogou wrote:
I tried to resize each control seperately but it didn't worked.
What happened ?
the WM_SIZE callback is the place to do it, maybe you get the wrong RECT ? in the handler, you get the client rect ( GetClientRect ), this will give you the client rect of the formview, once that's done, you MoveWindow each of the controls you want to move.
Max.
|
|
|
|
|
Any easy and quick way to write some bytes to the parallel port on windows 2000.
Should be an easy one....
Thanks in advance.
Shay Harel
|
|
|
|
|
hi everyone,
how do you create a right mouse click popup menu like ones that are use in most of the application, e.g. windows explorer, ie6..etc..
also, how do you disable a menu item in a menu(i.e. gray out the command in a menu)?
thx in advance.
|
|
|
|
|
There are several solution. One solution for a popup menu is a context menu. Search context menu in help or MSDN.
I do not have access to my source code right now. I can give you an example of a context menu tonight when I have access to my workstation.
Kuphryn
|
|
|
|
|
Lookup TrackPopupMenu on MSDN.
Jason Henderson start page ; articles
henderson is coming
henderson is an opponent's worst nightmare
* googlism *
|
|
|
|
|
Try this:
CPoint p;
GetCursorPos(&p);
CMenu menu;
menu.LoadMenu(IDR_MY_MENU)
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, AfxGetMainWnd());
note: the commands will be routed to the main window. To rout the commands to another place, replace AfxGetMainWnd() with a CWnd* of the window you want to get the messages.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
With Visual C++ Version 6.0 I face a problem that the next property page is not completely drawn after the message box has been closed. In the OnWizardNext() function I check the input fields and if an input is not acceptable I invoke an AfxMessageBox() function with Yes No button to continue or not. If the return value is IDNO I set the return value of the OnWizardNext() funtion to -1, so there is no jump to the next page. If the return from the message box is IDYES I set the return value to the default OnWizardNext() reurn wich is 0. Then a jump to the next page is performed but the next page is only partly drawn. The drawn area corresponds a pproximately with the rectangle including the controls in previous page.
Can some body give me indications how I can solve this problem ?
|
|
|
|
|
I have a CListCtrl embedded in a CFormView. Basically all I'm trying to do is make it so that long strings to not get cut off with a "..." at the end. In other words "The quick brown fox jumped over the lazy dog" will appear as "The quick brown fox jumped over ..." Pain in the butt it seems. Anyway if anyone has a solution to this problem, please respond. Thanks.
Mike
|
|
|
|
|
seems you are not familiar with the member functions.
See SetColomnWidth() member func
Hari
Hari Krishnan
|
|
|
|
|
If two applications running on one PC use the following bind call, what will happen?
sock.sin_family = PF_INET;<br />
sock.sin_addr.s_addr = htonl(INADDR_ANY);<br />
sock.sin_port = htons((u_short)0);<br />
<br />
if (bind(*lpSock,(LPSOCKADDR)&sock,sizeof(sock)) != SOCKET_ERROR)<br />
nRet = ENOERROR;
When a UDP message comes in with the dest. port of 2000 (for example), which application will get it (or will both)? I'm guessing that it cannot be determined/random? I really don't have any idea.
I realize this is a fairly basic sockets question but I have not been able to find any information on how this situation would behave.
Thanks for any info. you may have.
|
|
|
|
|
I think that no more than one application can bind to a given port at the same time.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Thanks,
since the port number is 0 here, doesn't that mean that it will attempt recv. from all port numbers?
|
|
|
|
|
Dave_ wrote:
since the port number is 0 here, doesn't that mean that it will attempt recv. from all port numbers?
Hm... have you tried using port 0?
You can't bind to port 0!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Yes, I have tried - we have software that has been running for years this way. The problem came up when another application sent/rcvd UDP messages at the same time. I'm guessing that they are using the bind with port 0 also (for the rcv socket), and they are getting some of the UDP messages that were meant for us.
|
|
|
|
|
Aah.. but then it must be specific for the UDP protocol to bind on port 0!
I don't know UDP that much.
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Thanks anyway. Maybe I will post another message with UDP and port 0 in the heading. This is very difficult to find any information on since 90% of programmers are using TCP instead.
|
|
|
|