|
Honestly, I am not sure if trying to do this in SSE will help. With many of your if statements, you would have to unpack from the xmm1, ... registers and this may wind up costing more processor time.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi.
I am not sure about this. I have a Cedit derived class in a DLL. In this I want to add a member of a keypad class I made. But I would like that EVERY CEdit derived class will only use ONE copy of this keypad. Can this be done just by declaring the keypad as a static member. Then when something it is entered into the keypad, it will be sent to the perspective Cedit class.
Can someone help me shed some light on this?
Thanks ahead of time.
Stan the man
|
|
|
|
|
A static member would work well.
You could keep a static reference count as well which tracks how many edit controls are in
existence (initialize to 0). When an edit control is created increment the reference count. If
the count is now 1, create the keypad. When an edit control is destroyed, decrement the count,
and if it's 0, destroy the keypad.
The edit controls can set another static variable when they gain focus, so the keypad knows which
one to direct input to.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Is it possible for me to decalre the keypad class in the edit class with a static? I would like to have the edit class somehow manage the keypad.
Ex:
class Keypad
{
}
class Edit
{
static Keypad;
}
...
Is there someway to do that? Or do I have to manage the keypad in my mainfrm class or something?
This way, when I declare an edit class, the keypad is "built in" but only has one copy (for memory sake) even with many edit controls. The keypad will direct the inputs to the correct parent.
Thanks.
|
|
|
|
|
Like you've shown it is what I was thinking...
class CKeypadWnd : public CWnd
{
};
class CKeypadEdit : public CEdit
{
static CKeypadWnd *pKeypadWnd;
static int KeypadRefCount;
static CKeypadWnd *pActiveKeypadWnd;
...
};
...
// In the CPP file:
CKeypadWnd *CKeypadEdit::pKeypadWnd = NULL;
int CKeypadEdit::KeypadRefCount = 0;
CKeypadWnd *CKeypadEdit::pActiveKeypadWnd = NULL;
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
There's only a couple of reasons I can think of to share a class this way:
1) You're sharing data between the various CEdit objects
2) There are a lot of your CEdit objects in existance at a time and you're concerned with memory usage, performance (the time to create the keypad object), or memory fragmentation.
I try to avoid static members unless the class is intended to provide static methods. If it were me, and if item 2 is the issue, I would dynamically create a single application global instance of the keypad and just use it wherever it's needed.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Actually, I do have lots of Edits. But I wanted to have a simple way to just declare each edit and then have the keypad function all built in without additionally allocating it again globally and then tie it to each Edit somehow.
Thanks for all the responses and comments!
|
|
|
|
|
Well, once you allocate your CEdit iobject on the heap, everything inside it also resides on the heap, so you can declare your keybad object like so:
class CMyEdit { private: CMyKedPad m_KeyPad; };
...and then initialize it in the CMyEdit constructor.
At that point, there's no overhead involved in allocating that object on the heap, and you don't have to worry about delete/null it when your CMyEdit object cleans itself up. My guess is that your KeyPad object doesn't contain much data, so it's not like multiple instances is going to take up much space (probably less than 64 bytes).
I still see no need for a static object (which is my entire point).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Well, the keypad will be a dialog of sort (enable touchscreen capability). In this case, would you still think a static is not necessary and then just declare the kaypad class in the Edit class?
Thanks.
Stan
|
|
|
|
|
hi, may be i'm a crazy idiot, but is there a way to change a funtion code and use it while running my project??
I buit a project to use a function such as "void cal(int a, int b) " stored in "cal.h"
first my project create a new header file like "cal.h" , it changes this function to "void cal(int a,int b,int c)" and its code too; second i want to use that func after updated and don't want to exit project.
But i'm only change this header file on the first step, then to use it i must compiled again. hic.
i've still not found a method yet, hic.
and..sorry for my bad English
|
|
|
|
|
what do you want to do exactly?
I mean do you want to change values iside your programm while running?
Or do you want to use different Functions depending on s.th.?
|
|
|
|
|
Do you mean edit and continue?
While running an application you can stop at a breakpoint in the debugger, edit the code, and
continue running with the new code.
Make sure edit and continue is enabled in the Tools/Options property pages.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
N.D.Quan wrote: I buit a project to use a function such as "void cal(int a, int b) " stored in "cal.h"
first my project create a new header file like "cal.h" , it changes this function to "void cal(int a,int b,int c)" and its code too; second i want to use that func after updated and don't want to exit project.
no thats not possible, but you can use argument list to achieve same ..
type va_arg(<br />
va_list arg_ptr,<br />
type <br />
);<br />
void va_end(<br />
va_list arg_ptr <br />
);<br />
void va_start(<br />
va_list arg_ptr <br />
);
void va_start(<br />
va_list arg_ptr,<br />
prev_param <br />
);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
|
Hello @ All!
I hope someone can help me in understanding how things work. So ich try to explain my problem.
I have an application written in c++. Implementing an interface gives access to a callback function.
So I'm called back when new data is available.
No comes the part where I have to put my hands on. In this Callback I copy the data and pass it to various functions. At the end of passing&calculation i have calulated some information. this information I want to give to an TCP or UDP Server. So the serverdata has to be updated each time i have calculated new data.
so i have experimented with the winsock tutorials... but how can i integrate the server in my running application whitout blocking it? Do I need two threads/processes or callbacks or events or even functionpointers? Has anyone suggestions on which to investigate ?
Thanks a lot
|
|
|
|
|
You may want to do some studying: Windows Sockets 2[^]
There's a variety of ways to handle sockets without blocking the application.
You may or may not need multiple threads depending on the communication demand on the CPU.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Study of that stuff is niche but does not fit my needs. I have an app running and want to include the server into this app in a way the rest can still do what it has to do..
Greetz
|
|
|
|
|
// This is file example.h
inline void f() { ... } // definition of f
If i include the above header file into example1.cpp and example2.cpp in a aproject and build the project why does the linker not give an error of redefinitation assuming the compiler has inlined the funtions.
Assuming the functions are not in inlined by the compiler then they shall become static to each file. This introduces the overhead of functional call and also of making the function f() static in the translation unit of both the files according to the old rules. With new rules there is something called out of line copy of function f() that shall be generated.
Can someone shed light on the case on the scenarios and what happens when inlined functions are rejected by the compiler.
|
|
|
|
|
Hi,
First, you don't need the keyword inline in the Headerfile if you use the {//impl.} in the headerfile.
void f(){} in a header is already inline.
Now to the include statement... what do you think does include mean???
hmm... I thik it means substitude this code here... Because you could
write the code you write in a headerfile as well in the cpp file.
So you have your' code included in the first and in the second cpp file.
Hope this helps...
Greetz
|
|
|
|
|
there's a lot of info in the MSDN for this, under the "inline" keyword.
here's some of it:
---
Even with __forceinline, the compiler cannot inline code in all circumstances. The compiler cannot inline a function if:
The function or its caller is compiled with /Ob0 (the default option for debug builds).
The function and the caller use different types of exception handling (C++ exception handling in one, structured exception handling in the other).
The function has a variable argument list.
The function uses inline assembly, unless compiled with /Og, /Ox, /O1, or /O2.
The function is recursive and not accompanied by #pragma inline_recursion(on). With the pragma, recursive functions are inlined to a default depth of 16 calls. To reduce the inlining depth, use inline_depth pragma.
The function is virtual and is called virtually. Direct calls to virtual functions can be inlined.
The program takes the address of the function and the call is made via the pointer to the function. Direct calls to functions that have had their address taken can be inlined.
The function is also marked with the naked __declspec modifier.
---
|
|
|
|
|
Hi,
I have the following situation.
class CPCntPPg : public CPropertyPage
{
DECLARE_DYNCREATE(CPCntPPg)
// Construction/destruction.
public:
CPCntPPg();
~CPCntPPg();
// Dialog Data.
//{{AFX_DATA(CPCntPPg)
enum { IDD = IDPP_PCNT };
CVQProgress m_ctlVQProgress; // CStatic derived class.
//}}AFX_DATA
CEdit m_ctlVQ[VQPNUM];
CSpinButtonCtrl m_ctlVQSpin[VQPNUM];
int m_nVQ[VQPNUM];
:
// Overrides.
// ClassWizard generate virtual function overrides.
//{{AFX_VIRTUAL(CPCntPPg)
public:
virtual BOOL OnApply();
protected:
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support.
//}}AFX_VIRTUAL
// Implementation.
protected:
void InitPPgData(); // Initializes the property page.
void InitSpinButtonCtrls();
:
// Generated message map functions.
//{{AFX_MSG(CPCntPPg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
afx_msg void OnChangeVQ(UINT nID);
:
DECLARE_MESSAGE_MAP()
};
// EN_CHANGE handler. When the contents of an edit control is changed by the user I want the
// m_ctlVQProgress control to redraw itself to reflect the changes.
void CPCntPPg::OnChangeVQ(UINT nID)
{
int nVQ; // Contents from changing edit control retrieved by GetWindowText() and
// _ttoi().
:
m_ctlVQProgress.SetVQ(nIndex, nVQ, TRUE /*Redraw*/); // This will initialize a data
// member and redraw the control.
}
The problem is when the edit control is set to an initial value by DDX/DDV in OnInitDialog
the OnChangeVQ handler gets also called causing the m_ctlVQProgress control to draw itself. This
happens before the OnPaint handler of the m_ctlVQProgress control is invoked. Is there any way to prevent this from happening ?
TIA
|
|
|
|
|
What's different about the initial state of the progress control compared to when a change is
made to the edit control later by the user?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
What is cache hit rate in inling and why does too much inlining can also reduce your instruction cache hit rate, thus reducing the speed of
instruction fetch from that of cache memory to that of primary memory.
|
|
|
|
|
Where did that question come from?
Are you talking about registers?
Inlining is basically like macros, where it injects the instructions into the code instead of calling the actual function, which could produce bloating, but will reduce the cost of calling a function.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Steve Echols wrote: Where did that question come from?
The same place that all of his questions come from. There seems to be no rhyme or reason behind them, other than for the sake of asking a question.
"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
|
|
|
|