|
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
|
|
|
|
|
"Cache hit rate inlining"
I would describe it as a technique used to avoid conditional jump instructions and reducing function call overhead.
Here are some reasons how/why __inline functions can possibly make code faster.
1.) In machine code when you conditionally jump from one address to another, the cpu branch predictor may choose the wrong path and will not prefetch the correct instructions. This is known as a cache miss.
More on cpu branch prediction:http://en.wikipedia.org/wiki/Branch_prediction[^]
2.) There 2 types of function linkages in machine code. The first is a leaf function. A leaf function is a function that does not call any other function. Its the end of the line or 'A leaf' like on a tree. This function may (possibly)be linked differently than other functions by the compiler (it may be inlined depending on the choice of the compiler). The second type of function is a non-leaf function which is calling other functions inside its body. It looks visually more like a tree branch with other branches or leaves atatched. (At least in my twisted mind!)
Now... When you call a non-leaf function linkage (most leaf too), the first thing that happens in __asm code is the function-prologue. The stack and registers are prepared for usage. http://en.wikipedia.org/wiki/Function_prologue[^]
As you can imagine... this requires some cpu cycles... which = time.
After the function has executed... the function must restore the stack and registers to its previous state... so the function who called it can continue processing! Otherwise the function which called function 2 would be completely confused. All of its registers and the stack would be different!
Here is an example from a project I am currently working on demonstrating a prologue and epilogue in a function.
A function which has been __inlined (if it was actually inlined) does not have this prologue/epilogue overhead.
Now you also asked how __inlining functions can cause increased cache misses. Well, __inline functions make code much larger. The increase in code size may cause a small, critical section of code to no longer fit in the cache, and this will cause cache misses!
Hope this helps,
-Randor (David Delaune)
|
|
|
|
|
Why is writing a function that returns a dereferenced pointer is a memory leak just waiting to happen. The function here initializes a reference to the object returned. In that case is the only alternative left is to return objects by value. When is it that objects are returned by reference and when is it that they are returned by value.
|
|
|
|
|
first of all, you never return a reference to an auto object( one created on the stack) because once you leave that scope, the object self destructs and you're left with a reference to nothing!
also you should not create an object on the heap and then return a reference to that object, because then you will have a memory leak because the allocated memory is never freed, the object done not self destruct when the reference goes out of scope!!!
would be cool if it did, but it doesn't.
so return a object on the stack, make sure the object can copy itself correctly if you're going to return objects by values, that is make sure the object has a copy constructor that does all the right things if you're doing anything specialized with that object, otherwise the complier will try to do a good job in trying to copy only auto class members, for pointer only the what the pointer points to will get copied but not what is pointer do! this is call a shallow copy....a deep copy is something that makes a copy of the pointer to things, but you will not have to worry about this when you're returning objects by value.
you will have to worry about this if you're want to clone an object, then you need to do a deep copy!
Yours Truly, The One and Only!
|
|
|
|
|
Why is a reference then returned in case of assigment operator where a dereferenced pointer is returned?
|
|
|
|
|
good question, in this case you're either dealing with the same object or an object that has been passed in. The main point is this object existed before it enter the function scope!
think about it!;P
Yours Truly, The One and Only!
|
|
|
|
|
tom groezer wrote: Why is a reference then returned in case of assigment operator where a dereferenced pointer is returned?
Bad example. That's not required in an assignment operator - it's customary, so you can use
the result on the right side of another assignment operator.
From the docs:
"The operator returns the object to preserve the behavior of the assignment operator, which
returns the value of the left side after the assignment is complete."
Assignment operators for a class can be overloaded to take whatever argument type you want and
return any type. For example:
class A
{
int integer;
public:
A() {integer = 0;}
int GetInt() {return integer;}
A &operator=( A &a )
{
integer = a.integer;
return *this;
}
int operator=( int i )
{
integer = i;
return i;
}
};
class B
{
double dbl;
public:
B() {dbl = 0.0;}
B &operator=( double newdbl )
{
dbl = newdbl;
return *this;
}
B *operator=( B *b )
{
dbl = b->dbl;
return this;
}
B &operator=( A &a )
{
dbl = (double)a.GetInt();
return *this;
}
};
...
A a1;
A a2;
B b1;
B b2;
a2 = 3;
a1 = a2;
int i = a1 = 4;
b1 = 1.25;
b2 = 2.50;
B* bp = b1 = &b2;
b2 = a1;
With power, comes responsibility
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
In your second exapmle u r returning a reference to a object allocated on the heap. IS it correct. Will it be correct if I retruned the same way from other functions of a class or is it that we could this only in assignment and copy constructor. what is the bottomline?
|
|
|
|
|
I use 4 objects, all are on the stack. No objects are heap allocated.
tom groezer wrote: Will it be correct if I retruned the same way from other functions of a class or is it that we could this only in assignment and copy constructor.
The same scoping and memory management rules apply as anywhere. It's up to us as programmers to
keep track of that.
Returning a reference or pointer to an automatic (stack) variable isn't going to work if the
caller tries to use it. The object has gone out of scope so it doesn't exist.
Any objects created in a function and returned to the caller need to be cleaned up somehow.
The assignment operator example was meant to show that you can use any argument or return value.
Doing so beyond a normal assignment can make code hard to read. An assignment operator for a
window class that takes a document object and returns a file pointer isn't going to make much
sense, but you can do it. You can also do anything you want in the implementation - you don't
have to actually assign anything. Again, it would add confusion - we normally expect '=' to
do an assignment.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Hi all. Im trying to make something that will have a random word every time it starts up. I made a two word array and its not working like i had hoped.
<br />
#include <iostream><br />
using namespace std;<br />
<br />
char* randomlist[]={<br />
"Test", "Testing"<br />
};<br />
<br />
<br />
<br />
int main(){<br />
cout << "Random list is: " << randomlist << endl;<br />
system("pause");<br />
return 0;<br />
}<br />
With the output of:
Random list is: 00475DC0
Press any key to continue . . .
Hardly what im trying to do. Any suggestions? Thanx in advance!
|
|
|
|
|
I'm a C programmer rather than a C++ programmer (so bear with me :p)... but wouldn't you have to specify in cout which array element you would like to print.. eg randomlist[0] or randomlist[1].. because at the moment I assume that it is just printing the pointer to randomlist to the screen..
Hope this helps!
--PerspX
"Nowadays, security guys break the Mac every single day. Every single day, they come out with a total exploit, your machine can be taken over totally. I dare anybody to do that once a month on the Windows machine." - Bill Gates
|
|
|
|