|
I'm building a VC++6 MFC application and trying to run it I received the message in the Subject line:
stack overflow
What can I do to avoid such messages?
How to check the stack and to set it.
...in VC++6, please...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Are you using some kind of recursion ? If yes, check if the recursion ends at some point. If that's not the case, you will never end calling the function which need some storage on the stack, until the stack is full.
That's one of the possible cause of stack overflow.
|
|
|
|
|
No. It isn't that case. Actually, I modified from the previous stable version some tables, making them permanentlly, instead of initialising locally with new or malloc() .
Can be a possible cause, too many global variables?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
It's possible that your program itself can allocate too much memory on the stack. I once wrote a performance test driver to perform a bunch of operations by iterating through a memory cache with a HUGE array of integers. I believe it compiled OK, but at runtime, it failed with that error. Check that you aren't allocating any huge arrays, and by that I mean in the area of 30000+.
|
|
|
|
|
If you've eliminated any recursion problems and simply need a
larger stack, you can set a larger stack size in your linker
options. Note the default stack size is 1MB.
See /STACK (Stack Allocations)[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks!
The message appear immediately after PreCreateWindow
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: I modified from the previous stable version some tables, making them permanentlly, instead of initialising locally with new or malloc()
Putting them on the stack didn't make them any more permanent than using dynamic
allocation.
In general, it may be better to use dynamic allocation (the new operator)
for large objects instead of using the stack. That way you don't have
to micro-manage your stack size. You want your stack to have some
breathing room. Use the heap - that's what it's for.
What's considered a "large" object? Opinions vary
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Finally I resolved the problems by dinamically alocating the "guilty" tables.
A final question. I didn't find in my "old" VC++6 how to use the
/STACK
option for the linker. Do you know how?
Thanks for all
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: A final question. I didn't find in my "old" VC++6 how to use the
/STACK
option for the linker. Do you know how?
I don't remember where it's at in VC6. Should be somewhere in the linker
settings for your project - look for a stack size option
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
OK Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
During the creation of my Combo Box I entered the data into it for selection of the User. How do I find out what the User selected?
Please provide some code please.(VS 6.0 and VS 2008 C++)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Do you want to get value or focus on combobox?
|
|
|
|
|
When the user changes the selected item, the parent will receive a CBN_SELCHANGE
notification (in a WM_COMMAND message). In response to that notification,
or at some other time you need the selected item from the combo box, you
could do something like this:
LRESULT SelectedIndex = SendMessage(hwndComboBox, CB_GETCURSEL, 0, 0);
if (CB_ERR != SelectedIndex)
{
LRESULT StringLength = SendMessage(hwndComboBox, CB_GETLBTEXTLEN, SelectedIndex, 0);
TCHAR *pSelectedString = new TCHAR[StringLength + 1];
SendMessage(hwndComboBox, CB_GETLBTEXT, SelectedIndex, (LPARAM)pSelectedString);
delete[] pSelectedString;
}
All Windows controls have associated messages used to manipulate them. Unless you
have them all memoized, I recommend keeping a link to this: Windows Controls[^]
or know where to find it in your local documentation.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey!
Well i dun ve visual studio 08. But i can provide you a help in visual studio 6.0.
Now as you have already entered data to the combo box.Add new variable for the Combo Box in class wizard. it can be of type VALUE or CONTROL. Let it be VALUE and type CString. This variable will hold the data present in the Combo Box.Let the variable is ComboBox_Variable.
Now to check what user has selected, you can put a simple event in your program which will help in finding what user has selected from the box.
so you can add a button which will show a simple messagebox depending on the combo box data. Like a button named "Message".
Add an event handler for it and you can use the following code.
<br />
CString example;<br />
example = ComboBox_Variable;<br />
if(example=="Data-1")<br />
MessageBox("Data-1 selected by user");<br />
else if(example=="Data-2")<br />
MessageBox("Data-2 selected by user");<br />
You can use switch statement too!
I hope Combo Box will be clear to you now!
|
|
|
|
|
I have DVD-Compliant Mpeg-2 Files that I am interested in "turning" into .Vob files.
I know that these are basically the same and that the difference is in the "headers" of these two file types.
All of the Third-Party SDK's i have found demux and remux the mpeg before converting it to .vob.
I know that there are open-source libraries that create vob files and unofficial specifications for .vob files but for something so simple how can there not be a library or sdk that can save me the troubles?
Bottom line - I am looking for Code\module\dll\sdk that converts Dvd-Compliant Mpeg-2 files to .vob files.
Thank you,
Michael Mimouni
Witech Developer
mjmimmm@hotmail.com
|
|
|
|
|
class Text {
public:
void bad( const string &parm ) const;
private:
char *_text;
};
void Text::bad( const string &parm ) const
{
_text = parm.c_str(); // error: _text cannot be modified
for ( int ix = 0; ix < parm.size(); ++ix )
_text[ix] = parm[ix]; // bad style but not an error
}
this example show a pointer refer change a data member in the
const member function , why?
|
|
|
|
|
the function is declared as const (void Text::bad(const string& parm) const; ), that means that it is not allowed to modify any members of the Text class.
exception is with the mutable members however.
modified on Sunday, December 09, 2007 11:13:17 AM
|
|
|
|
|
_text is a char*. The const member promises not to change any of the member variables. Your first assignment changes _text to point to a different string. The second assignment (in the loop) does not change _text, but the content of the string that _text points to (btw, I assume that _text has been assigned to a valid string at some point in code not shown, otherwise the second assignment will corrupt your memory).
const pointers can point to mutable objects. You may change content of the object, but not the content of the pointer.
Cheers
Steen.
"Are you gonna check your makeup when you're done whining?" John Simmons, 05/31/2006
"Of course, the next day it automatically updates, and your quick'n'dirty patches cause the new binaries to segfault all over your linoleum. If only you'd had the source..." Shog, 10/18/2006
"One day I realized that sadness is just another word for not enough coffee" Wally, 10/18/2006
|
|
|
|
|
Hello,
I have run this logic on turboc++ 3.0 and it is working fine on it but
its not running on msvs2008 c++.
the code does this::
the fun strrep takes 3 char arrays the i.e main,sub,rep.
the sub array is to be found out i the main array and if found its index is taken on found pos,(this is achieved by the searchsub function separately)
then the sub array is replaced in the main array by the rep array,and the rep array can be of different size from the sub array.
i am not able to assign the value like this *temp=*main,where main and
temp are char pointers.
there is a runtime access violation error on msvs..that i am not
able to work out how to resolve..
kind attention and feedback would be invaluable for me...
thanks...the code is as below..
<code>// C++Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
int i;
int searchsub(char mainstr[],char fndstr[])
{
int mainlen=0,sublen=0,flag=-1,index=0;
for( i=0;mainstr[i]!='\0';i++)
mainlen++;
for( i=0;fndstr[i]!='\0';i++)
sublen++;
for(i=0;i<mainlen;i++)>
{
index=i;
if(mainstr[i]==fndstr[0])
{
for(int k=0;k<sublen;k++)>
{
if(mainstr[i++]!=fndstr[k])
{
flag=0;
break;
}
else flag=1;
}
if(flag==1)
break;
i=index;
}
}
if(flag==1)
return index;
else return -1;
}
char * strrep(char * main,char* sub,char* rep)
{
int sublen=0,mainlen=0,replen=0;
char* save=main;
char*temp;
for( i=0;*rep!='\0';i++,rep++)
replen++;
rep=rep-i;
int index=searchsub(main,sub);
for( i=0;*sub!='\0';i++,sub++)
sublen++;
sub=sub-i;
int reststrindex=index+sublen;
main=main+reststrindex;
for(i=0;*main!='\0';i++,temp++,main++)
*temp=*main;
*temp='\0';
main=main-i-reststrindex;
int templen=0;
temp=temp-i;
for( i=0;*temp!='\0';i++,temp++)
templen++;
temp=temp-i;
main=main+index;
for(i=index;i<index+replen;i++)>
{
*main=*rep;
main++;
rep++;
}
for(i=0;i<templen;i++)>
{
*main=*temp;
main++;
temp++;
}
*main='\0';
main=save;
return main;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<strrep("Abcdefghijk","cde","peternorton");
return 0;
}</templen;i++)></index+replen;i++)></sublen;k++)></mainlen;i++)></code>
|
|
|
|
|
how to post codes on this forum...my code is converting into html tags...
please look for this question on this link instead...
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/dddfd4d4b8098a4b#ce1679dc10ec66c0
thanks..
|
|
|
|
|
After you have written your question, select the code then click on the CODE label, below the Text entry window.
This causes the selected text to be treated as code.
|
|
|
|
|
Your code has two major problems: it tries to modify a literal string ("Abcdefghijk") and it will overwrite the area allocated for main if rep is longer than sub . Try this instead:
std::string& strrep(std::string& main, const char* sub, const char* rep) {
if(sub && rep) {
std::string::size_type idx = main.find(sub);
if(idx != std::string::npos) {
return main.replace(idx, strlen(sub), rep);
}
}
return main;
}
|
|
|
|
|
Thanks for replying markkuk,
Firstly i dont want to use any of the inbuilt functions.
secondly why cant i increase the memory space for the main char pointer if the rep>sub,as i think that pointers do give a programmer this ability.. or should i allocate a new memory space using new operator and then carry out the operations on main pointer??
and why this can be done without errors on turbo c++ 3.0 and not in msvs2008 c++??
thanks for showing interest and helping.
|
|
|
|
|
If I try to add some thing in my sample project the error displays like this:-> c:\documents and settings\administrator\desktop\mitumori\mitu\jpeg.h(21) : error C2370: 'kJFIF' : redefinition; different storage class
|
|
|
|
|
keyto wrote: error C2370: 'kJFIF' : redefinition; different storage class
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|