|
Thanks DavidCrow,
Data segment is some global space of a process, compared with function local stack space?
regards,
George
|
|
|
|
|
George_George wrote: I am wondering how C or C++ manages static variable internally.
Global statics are placed on the heap, not the stack.
They are initialized upon first use by the application.
They are destroyed upon exit from the application.
Whereas variables on the stack come and go, the heap hangs around until program termination.
I had thought Global statics were handled differently than Local statics, but I proved myself wrong.
Beware of INLINE statics, however. If the code is actually INLINED, the compiler may create multiple instances of the static variable storage, plus one that is global. This will no doubt lead to problems.
Gary
|
|
|
|
|
Thanks Gary,
ghle wrote: I had thought Global statics were handled differently than Local statics, but I proved myself wrong.
You mean global static variable and function local variable are handled in the same way by compiler?
regards,
George
|
|
|
|
|
George_George wrote: You mean global static variable and function local variable are handled in the same way by compiler?
George, both the global statics and local statics are placed onto the heap - by the compiler. I'd say they are handled similar, but not identical. For example, global statics are initialized at start-up of the program, but local statics are not initialized until they first come into scope. Both are destroyed only upon termination of the program, that is when the heap is destroyed.
You said "function local variable", but I mean function local STATIC variable. A function local variable - non-static - are pushed onto the stack not put in the heap. When the function goes out of scope, so do it's variables. Returning from the function to the calling program will pop the stack, removing all local non-static variables from existence. But the function static variables were put on the heap, and they still exist after the function goes out of scope, available to the routine/method once it comes back into scope from another call. (And as noted earlier in this thread, I found local statics were available from outside of the local function if the address of the static is returned by the method.)
Heap
Global statics
Main() statics
Method B statics
Method C statics
/Heap
<br />
Stack after calling Main()<br />
Main() non-static variables<br />
/Stack<br />
<br />
Stack after calling method B from Main()<br />
Main() non-static variables<br />
Method B non-static variables<br />
/Stack<br />
<br />
Stack after calling method C from B<br />
Main() non-static variables<br />
Method B non-static variables<br />
Method C non-static variables<br />
/Stack<br />
<br />
Stack after calling method C from method C (recursion)<br />
Main() non-static variables<br />
Method B non-static variables<br />
Method C non-static variables<br />
Susequent method C non-static variables<br />
/Stack<br />
<br />
Stack after returning from method C to method B<br />
Main() non-static variables<br />
Method B non-static variables<br />
/Stack<br />
<br />
Stack after returning to Main() from method B<br />
Main() non-static variables<br />
/Stack
Heap after returning to Main(). All statics now initialized.
Global statics
Main() statics
Method B statics
Method C statics
/Heap
Gary
-- modified at 8:43 Monday 27th August, 2007
|
|
|
|
|
Thanks Gary,
Your reply is great!
regards,
George
|
|
|
|
|
thanks for your advice and help,what do you mean by 'doh' if you have any idea about the registry cleaner please help me asap.
|
|
|
|
|
dear, you are wanting to clean the registry isnt it?
|
|
|
|
|
Registry Cleaner is an application that is responsible for cleaning up the invalid entries that exist in the registry. These invalid entries could be those that are left after uninstalling a software, could be an invalid entry in the Known Dll's key, could delete cookies, temporary internet files and blah blah....
You would need to figure out what do you want your registry cleaner to do.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
niki dutta wrote: thanks for your advice and help,what do you mean by 'doh' if you have any idea about the registry cleaner please help me asap.
have you have the clear requirement in your mind or written some where!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
niki dutta wrote: thanks for your advice and help,what do you mean by 'doh' if you have any idea about the registry cleaner please help me asap.
what is you question ?
actually, i know you're not asking one ; you were replying to someone. but then WHY don't you follow the same thread instead of starting a new one ?!
don't matter the thread moved on the second page and not visible directly anymore, because the guy you replied to will receive a mail as a notification...
|
|
|
|
|
Do you need to tool for clean registry? or its nit your question?
|
|
|
|
|
niki dutta wrote: if you have any idea about the registry cleaner please help me asap.
Stop this nonsense. Ask an intelligent question, or don't bother posting. No one is going to do your work for you so stop asking. If an article is not working for you, contact its author.
"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
|
|
|
|
|
i have 20 edit box on my dialog, it was formated into 4 rows with 5 edit box with each row.
these edit box displays integers. i want to save/load the integers to/from a .txt file.
the .txt file should have the following format,each number corresponds to each edit box, and each row corresponds to each row of edit box:
50,5,3,2,6
32,56,7,8,9
12,34,56,7,9
1,2,4,5,6
1,2,3,4,5
the numbers are just above is just an example.
How i do this?
thx
|
|
|
|
|
Did you try anything yet?
You can just read the file to get each values and set to each edit control.
Where did you stuck?
- NS -
|
|
|
|
|
what have you done so far to achieve this ?
|
|
|
|
|
i've made a button to open a cfiledialog box,and assoicate a CFile with a CArchive
<br />
if( FileDlg.DoModal() == IDOK )<br />
{<br />
if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )<br />
return;<br />
CArchive ar(&f, CArchive::load);<br />
.....<br />
after this, i don't know the exact the syntax to load the data from the .txt file.
is it better to create a data buffer and then load the data into the data buffer?
i wish to seperate the data by comma and clarity, but of course i don't want to load the commas, what's the syntax??
thx
|
|
|
|
|
alberthyc wrote: 4 rows with 5 edit box with each row.
Note: your example data is 5 rows with 5 edit boxes each.
First time getting data from a file, eh?;P
<br />
if( FileDlg.DoModal() == IDOK )<br />
{<br />
if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )<br />
{<br />
return;<br />
}<br />
char cBuffer[MAX_SIZE];
if (f.GetLength() > sizeof(cBuffer))
{
AfxMessageBox("I theenk I need a beegger box!", MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
} else {
if (f.Read(cBuffer, sizeof(cBuffer)))
{
int ia=0, ib=0, ic=0, id=0, ie=0;
if (4 == sscanf(cBuffer, "%d,%d,%d,%d,%d\n", ia, ib, ic, id, ie))
{
}
}
}
<br />
}<br />
Gary
|
|
|
|
|
Hello guys,
Good day to you. I have a coded an MFC application which uses the XML library to create XML data and send it through TCP/IP. Now, I need to compile the code and create a .exe that will run to another PC which unfortunately has no Visual Studio installed.
I tried this before with another code and it worked just by setting on the project settings -> use static library. Though the problem with my current code is that it pops-up this error:
cl : command line error D8016 : command line option '/MTd' and '/clr:oldsyntax' cannot be used at the same time
Now, I solved this problem but it made another. As it turns out, somehow I am using managed code with unmanaged (I dont know if the term is right) which I cant.
Please help me with this, I just need to create the .exe file for another PC without VS. Thank you for your time.
|
|
|
|
|
I tweaked some options and replaced /MTd with /MD. And it works with the use static library for MFC. Though I tried to run it in another PC without VS but it still does not work. I really need to deploy this and installing the whole VS in the target PC is not an option. Does anyone have any suggestions? Like maybe creating the installer for my project or something. Thank you very much.
|
|
|
|
|
If you are using MFC based application than it is necessary to install some dll on another pc. on C:\windows\system32. MFC42D.dll , ole32.dll
may be it will work.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
There is a tool in Visual Studio 'Depends' which can be used to find out the dependant dlls of your executables. You can find the Depends.exe in Visual Studio Bin Folder. Just Drag and drop your executable into the Depends window to show the list of dependant dlls. Though it lists all the dlls the exe uses certain common dlls like user32.dll and kernel32.dll will be available in the target system.
You need to find out MFC dlls normally these dlls are needed for an MFC application
MFC42D.dll,MSVCRTD.dll, MFC042D.dll (These are debug mode dlls, release mode uses the corresponding dlls with out 'D' in the name)
If you copy all the required dlls and your executable in a singlre folder and try to run this exe from your end system with out VS, this should run.
Some times if you are using some com components as part of your exe, you need to copy that com dll also to the end system, and have to call regsvr32 to register that com component on the end system before trying to execute your program
From your query, its not clear what is the error coming when you are trying to run your exe on User System with out VS?
Cheers, Arun Krishnan
|
|
|
|
|
BTW, never distribute an exe that has been built in Debug mode !
|
|
|
|
|
Finally solved it! I was never aware of this Depends.exe. Thank you very much for the help! This is just what I am looking for. Again, thank you for the time and help!
|
|
|
|
|
try to open the exe in dependency viewer and note all the dlls used by that exe. On another pc all these dlls need to be present..
dependency viewer is available in vc++ 6 tools
|
|
|
|
|
Yes. Its placed inside the tools folder, it's the first time I encountered this application. Thank you for the help and time!
|
|
|
|
|