|
It is N*N loop aready with N=10000 it is 10,000*10,000 = 100,000,000 operations.
That already takes 170 ms to process.
I need to optimize code that performs even less operations.
Чесноков
|
|
|
|
|
Missed that. I need glasses
Ash
|
|
|
|
|
I used RegisterHotKey API to provide hot keys for certain events.
If i dont close my application and if i run another then CTRL + C is not working cause i am using it in my application. What shall i do?
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
I think you are confusing between hotkeys and accelerators: the first one are system-wide key escapes, the second one are limited to the application.
|
|
|
|
|
Oh, so what do we do if we want the key using registerhotkey to be local to the application and not all other applications... or how do we use accelerators like hotkeys... i have not yet experimented accelerators. can you give me an online reference so that i can go through that and use it. thank you.
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Accelerators are quite easy to use; the steps required are the following:
- create a new resource of type accelerator table inside your .rc file, then add the entries that you want to that table using the resource editor
- load the accelerator table using the
LoadAccelerators function - inside the message loop of the window that you want to process the accelerators, use the
TranslateAccelerator function to dispatch them
You can read the documentation about accelerator here[^] on the MSDN.
Note: if you are using MFC and your application is based on the document/view architecture, then the project wizard alerady creates an accelerator table for you, and that table is already loaded and used by your frame window (see Managing Menus, Control Bars, and Accelerators (MFC)[^] on the MSDN). If your application is an MFC dialog based one, you should manually add the code to load the accelerator table (you can call LoadAccelerators in the constructor of your CDialog derived class) and to dispatch the accelerators, by overriding the PreTranslateMessage virtual method and calling TranslateAccelerator .
|
|
|
|
|
Wow, thats a nice explanation.
Thank you.
Let me play with those functions and let me try to accomplish my task.
http://vikku.info/
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
How to get the Selected Item from CListControl
when scrolling through key board arrow keys.
I want to know the selected item no when scrolling through keyboard.
Using mouse click I can able to get the selected item no.
|
|
|
|
|
CListCtrl::GetSelectionMark[^] doesn't work for you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I know its not correct.
-> But can a pointer, to a class which contains only member functions and absolutely no data members, be used to invoke its member functions?
int func_2(int i, float j)
{
cout << i << j << endl;
return i;
}
class ABC
{
public:
int func_1(int i, float j)
{
return func_2(i, j);
}
};
[1] ABC *pObj;
[2] int i = 10;
[3] float f = 20.50f;
[4] int r = pObj->func_1(i, f);
When the above code is executed using VC++2003(version 7.1) following error occurs at line[4]:
Run-Time Check Failure #3 - The variable 'pObj' is being used without being defined.
but even if the error is ignored\ continued then also every thing work properly.
Please suggest :
->Whether this method of using uninitialized pointer is acceptable in any condition?
->Will this work on different platforms?(could not try this, since I do not have accesses to other platform)
->Any pitfalls?
->Your Valuable suggestions.
Thanks in advance.
|
|
|
|
|
Technically it can be used this way.
But if such a situation arises, you should make the function a static function and call it using the class scope operator.
The error is issued because these things usually tend to become bugs.
|
|
|
|
|
I thought there must be an instance of an object to use a pointer to one. Even with a static member that is not the best syntax to use though. I hesitate to say correct because I am not a language expert.
To use a static method the usual syntax is ClassName::MethodName(); when no instance is referenced.
|
|
|
|
|
Rick York wrote: I thought there must be an instance of an object to use a pointer to one.
If the function which is called do not access any members of the class, then it is "safe". But of cours it is absolutely bad practice.
Rick York wrote: Even with a static member that is not the best syntax to use though.
This, on the other hand is perfectly acceptable.
I should take a coffee before answering questions on CP . This is not that acceptable, since the static function should accessed this way: ClassName::MethodName()
|
|
|
|
|
Cedric Moonen wrote: This, on the other hand is perfectly acceptable.
However, the wise developer would use the classname::method syntax.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I think I was not awake when I replied, I really thought he was talking about accessing the static function using the classname::method syntax. Pff, ok, I'll fetch a coffee now.
|
|
|
|
|
I can barely reach my workstation, without caffein.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
With the risk of being wordy...
This piece of code should illustrate things.
class Z
{
public:
int g;
void out(){printf("addr %p\n", this);}
void outg(){printf("addr %p g=%d\n", this, g);}
};
Z *pz1, *pz2=0, *pz3=(Z*)0xdeadbabe, *pz4, z;
void main()
{
pz1->out();
pz2->out();
pz3->out();
pz4->out();
z.g=100;
pz1=&z;
pz1->outg();
pz2->outg();
pz3->outg();
pz4->outg();
}
As you can see, pz1 to pz4 are either not initialized or are initialized to "wrong" values. However, lines 1 to 4 execute happily, even though you dereferance using these wrong pointers. Thats because you aren't actually touching the member variable at all.
Now, look at what happens next. At line 6, pz1 is initiated to a valid address and hence outg() doesn't complain. Why should it complain you may ask. I'll tell you.
Open the disassembly window and step into the function call at line 8. There you'll find that the control actually steps into the function, even when derefeneced using a wrong pointer! Thats because one line of C/C++ translates into many many lines of assembler. As you step past each assembler instruction, you'll encounter this instruction
mov ecx, dword ptr [eax]
and that is where you get the tantrum.
In this line, the member variable 'g' is attempted to be accessed. EAX really holds the address of the object but because 'g' is the first member, the address coincide. And the complaint is valid as you cannot CANNOT SHOULD NOT access data from uninitialized memory.
EDIT: I forgot to mention that you have to turn off "incremental linking". It doesn't matter much except that if its on you might get confused and/or distracted by the " @ILT+nnn " that you'll encounter. An oh, its MSVC6.0
...byte till it megahertz...
modified on Thursday, August 5, 2010 3:33 AM
|
|
|
|
|
|
ccpptrain wrote: ->Whether this method of using uninitialized pointer is acceptable in any condition?
It is acceptable as long as you are careful, as you promised absolutely no data members. With this condition, you initialize or don't initialize or simply call using 0 (zero) pointer, it is acceptable.
ccpptrain wrote: ->Will this work on different platforms?
It is same for all platforms.
ccpptrain wrote: ->Any pitfalls?
One more promise: don't delete the pObj.
ccpptrain wrote: ->Your Valuable suggestions.
Don't do like this. You never know when you are going to add member variables and access them.
|
|
|
|
|
my app crashed, i suspect some of const class members are not initialized.
actually, compiler can not detect uninitialized const pointers, i.e.
const CWnd*pc;
as class member, but there is no error if forgot to initialize it.
why? - I don't think that default value of NULL is good reason to allow code above be compiled.
so I did a test inside a function, which shows no error:
const CWnd*pc0=0;
CWnd*pc1=(CWnd*)100;
pc0=pc1;
for other types of data, such as int, above code can not be compiled.
Any idea to solve the problem to make sure const pointer must be inilialized?
|
|
|
|
|
const CWnd*pc; here pc is not a constant pointer. It is a pointer to const CWnd object.
Constant pointer is declared as follows: CWnd* const pc;
|
|
|
|
|
Most compilers can detect use of uninitialised pointers. Try cranking the warning level up and flagging warnings as errors (/W4 /WX on VC++ and gcc IIRC).
If you want to make sure that pointers are initialised before use there is a solution - don't use pointers. There's really no reason to use raw pointers these days (apart from compatibility with code written in C). Pointers have three uses and there's a better solution for all of them:
- marking ownership - instead use a smart pointer, even std::auto_ptr is usable with a few caveats
- iteration - use containers and use iterators from the containers
- referring to other objects - use references if the object can't be rebound, a smart pointer if it can.
Now onto the const bit... You've read the type wrong. What you've got isn't a "constant pointer" but a "pointer to a constant object". C and C++ have slightly strange declarators in that you don't read them left to right but identifier outwards in precedence order.
Cheers,
Ash
|
|
|
|
|
Hello folks!
I used GlobalMemoryStatusEx[^] to get memory information. As the subject suggests, i am looking for the available physical memory my process may allocate, however, the ullAvailPhys member of MEMORYSTATUSEX[^] shows all the available memory bytes, not only the bytes allocatable by my process. So you understand, windows has a 2Gb (i know this can be increased to 3Gb but that's of no relevance right now) limit per process. So if my computer has 3Gb memory, my process allocates 1.5Gb, then i check the free memory size, i get 1.5G, but if i try to allocate that 1.5G, it will fail since only 0.5G is available to my process. I might be wrong, i am not sure, so please correct me if i am.
So i figured, if i take the smaller value of ullAvailPhys and ullAvailVirtual , this should give me the available physical mem for my process, but this is really a guess. So...can someone tell me how to do this correctly, or if this way is reliable?
Thanks for any info in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Which API did you call to allocate memory?
|
|
|
|
|
Well, the "default" implementation of new and malloc are mostly used for memory allocation as far as i know (what memory allocators 3rd party codes and windows API calls use is beyond me).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|