|
Ravi Bhavnani wrote:
Corrected link[^]
Thanks
"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
|
|
|
|
|
int x;
for(i=1;i<=10;i++)
{
x=i;
cout<
|
|
|
|
|
in the second case, it may allocate memory on different places, but as it is the system which decides, x may have the same address many times...
in C/C++, a variable declared in a local scope is destroyed when the program gets out of that scope. here, it the case at each loop of the for...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 6:11 Monday 5th September, 2005
|
|
|
|
|
Vivekuniq wrote:
int x;
for(i=1;i<=10;i++)
{
x=i;
cout<<x;
}< i="">
Here memory for variable X will allocated in Stack for entire LOOP duration
Vivekuniq wrote:
for(i=1;i<=10;i++)
{
int x;
x=i;
cout<<x;
}< i="">
Here the Memory of Variable X will allocated and deallocated in each cycle of loop!
"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
|
|
|
|
|
Again both came for race greate. I like you both.
Nice talking to you.
|
|
|
|
|
G Haranadh wrote:
I like you both.
Thanks for liking Us
"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
|
|
|
|
|
|
In the second case, variable i will still be on the stack. It's likely that it vill occupy the same memory address at every loop, since the stack doesn't change within the loop.
Or am I wrong?
|
|
|
|
|
kakan wrote:
It's likely that it vill occupy the same memory address at every loop, since the stack doesn't change within the loop.
purly depend on OS, AFAIK, Stack will be cleaned at every iteration!
"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
|
|
|
|
|
Yes, the stack variables will be cleaned, that's true. But the variable i will be recreated for every iteration of the loop.
That's why i beleive that the variable i will occupy the same memory address of the stack for every iteration.
It's the compilers task to handle the stack, depending on calling convention etc., not the OS.
BTW, the stack isn't cleaned or allocated (except when the process/thread starts and exits). So i think 'cleaned' isn't very appropriate. Referenced/dereferenced is better, in my opinion.
Pls do correct me if I'm wrong.
|
|
|
|
|
kakan wrote:
Yes, the stack variables will be cleaned, that's true. But the variable i will be recreated for every iteration of the loop.
That's Whats I am saying...
kakan wrote:
It's the compilers task to handle the stack, depending on calling convention etc., not the OS.
yeah I know but Compiler doesn't allocate address to the stack. That the Work of OS, you can correct if i am wrong..
kakan wrote:
the stack isn't cleaned or allocated (except when the process/thread starts and exits).
But PUSH and POP happens, i.e. variable is push and pop into/from Stack.
"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
|
|
|
|
|
It could happen both situations ... It also depends on the memory usage of others threads.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
hmmmm.... i get it .. n will be back with the next Qn..
thanx
V
|
|
|
|
|
The behavior here is dependent upon the compiler implementation. When you define a variable, two things happen. One, memory is allocated to store the variable, and two, the variable's constructor is called to initialize it.
For atomic data types, the compiler may in effect perform a single static allocation, just prior to the top of the loop. This allocation occurs by virtue of assigning the variable 'x ' a fixed offset from the stack pointer.
Regardless of how the memory is allocated, the compiler will call the constructor at the beginning of each iteration. Since 'x ' is of type int , the constructor doesn't do anything.
How the compiler allocates memory in this case should be immaterial to you. When a variable is defined inside the loop, you should treat it as if it were newly constructed. For simple int values, this means the variable is uninitialized, and you can't rely on it containing the results from the previous iteration.
Software Zen: delete this;
|
|
|
|
|
How to use CByteArray to store and retrieve unsigned char data
|
|
|
|
|
snprani wrote:
How to use CByteArray to store and retrieve unsigned char data
//To Store
CByteArray bytArray;
bytArray.Add(10);
bytArray.Add(11);
bytArray.Add(11);
//to retrieve
for(int i=0;i<bytArray.GetSize();i++)
{
cout<<bytArray.GetAt(i);
}
"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
|
|
|
|
|
A vc project using IHTMLDocument3 interface:
#include <mshtml.h>
//...
class CHTMLDocument2 : public CObject
{
//...
IHTMLDocument3* pHTMLDocument3;
};
When I building this project, report error messages as follows:
error C2143: syntax error : missing ';' before '*'
error C2501: 'IHTMLDocument3' : missing storage-class or type specifiers
And I find that there isn't class IHTMLDocument3 in the file <mshtml.h> of my compuer.
Is there anyone tell me how to upgrade <mshtml.h> and mshtml.dll to use IHTMLDocument3 interface?
Or other way to build this project successfully?
Thanks
Study! Study! Study!
Hard! Hard! Hard!
-- modified at 5:06 Monday 5th September, 2005
|
|
|
|
|
|
I have installed the SDK, and add the path of SDK to Tools-->option-->Directories include files, then when building, another error occurs:
error C2601: 'LONG_PTR' identifier ...
the 'LONG_PTR' appears in <mshtml.h> of SDK.
How can I resolve the problem?
|
|
|
|
|
on what line does it crash within your code ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
the error messages are partly listed below:
c:\program files\microsoft platform sdk\include\mshtml.h(40510) : error C2061: syntax error : identifier 'LONG_PTR'
c:\program files\microsoft platform sdk\include\mshtml.h(40513) : error C2061: syntax error : identifier 'LONG_PTR'
c:\program files\microsoft platform sdk\include\mshtml.h(40516) : error C2061: syntax error : identifier 'LONG_PTR'
...
The corresponding codes in the file mshtml.h is listed below:
virtual /* [nonbrowsable][restricted][hidden][id][propget] */ HRESULT STDMETHODCALLTYPE get_imeCompositionChange(
/* [out][retval] */ LONG_PTR *p) = 0;
virtual /* [nonbrowsable][restricted][hidden][id][propget] */ HRESULT STDMETHODCALLTYPE get_imeNotifyCommand(
/* [out][retval] */ LONG_PTR *p) = 0;
virtual /* [nonbrowsable][restricted][hidden][id][propget] */ HRESULT STDMETHODCALLTYPE get_imeNotifyData(
/* [out][retval] */ LONG_PTR *p) = 0;
How to resolve this problem?
Study! Study! Study!
Hard! Hard! Hard!
-- modified at 7:30 Monday 5th September, 2005
|
|
|
|
|
I have building this project successfully in the Visual C++ 7.0.
But I still would like to know how to fix this problem in Visual C++ 6.0.
|
|
|
|
|
You may need to change the values of the #define values WINVER , _WIN32_WINNT , and _WIN32_IE . These values control, at compile time, the availability of certain declarations. I typically use:
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0600 These specify Windows XP and Internet Explorer 6.0 and greater. The best place to set these is at the top of stdafx.h , before you have #include d any of the system header files.
Software Zen: delete this;
|
|
|
|
|
Hi,
Sorry I am posting this question again in VC++ thread, posted it earlier in COM section but seems like responses are bit slow in that section. Requesting all the readers to please answer my query if they feel they can provide some inputs.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I am using a third party COM component to connect to a remote SSH server. For this I have created a STA thread. Now I have a trivial user scenario, when the user issues a connect command a modal dialog is shown with a cancel button to display the status of connection. At anytime the user can press cancel button to abort the operation. Since the calls to cancel/abort are generally asynchronous the actual call to disconnect comes from a different STA thread. Now the problem I am facing is that the after the user clicks the cancel button the dialog is not getting disposed away and the thread is not stopping, thus my application hangs. If I attach a debugger to the release build of the application, the application breaks in the debugger with Invalid RtlHeapAddress. Initially I though it could be a problem of directly accessing my interface pointer, so I marshalled the interface pointer using GlobalInterfaceTable, yet the result is the same.
After some debugging I found that the call to Connect is not returning at all, to be on a safer side I have a message loops in my all STA threads.
How do I make sure that my dialog is disposed properly and my STA thread also stops properly.
I am using VC++ 6.0 for developing my application. The COM part is implemented using pure C++
Thanks
|
|
|
|
|
Hi,
1. Who creates Modal dialog box?. Is it created by the Connect method?
2. How you are sending the Cancel/Continue message to the STA thread? (I mean are you just using SendMessage/PostMessage). Use cannot use SendMessage and PostMessage on different thread. If you use, try PostThreadMessage).
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|