|
Each function call in a recursive loop consumes stack space. If you're passing parameters, that consumes even more stack space. I thought the max stack space for a given app was limited to 64k...
Of course, I'm old, so it may have changed since I last checked it out.
"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
|
|
|
|
|
In general, using recursion in pure imperative languages such as C++ is a bad idea - it can lead to stack overflows and also tends to be slower than iteration.
Functional languages such as OCaml are able to internaly convert recursion (at least tail recursion) to iteration and then it is OK to use recursion.
|
|
|
|
|
Well, I think there are definitely some very good uses of recursion in C++ such as generically printing out the data in an XML DOM tree, where there is no absolutely defined node structure. I'm not sure how you'd go about doing that otherwise. That said, DOM tree hierarchies typically don't go down that many levels -- that would be both a memory usage and usability nightmare.
|
|
|
|
|
Hi
I create new process (exe) with CreateProcess function.
now Iv got a handle (hProcess) and would like to know whether or not the process is alive?
|
|
|
|
|
Here's one way...
if (WAIT_OBJECT_0 != ::WaitForSingleObject(hProcess, 0))
{
// process is still active
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
Hello!
We have 2D array, Data[20][10], it contains some values, want some suggestions on how to count the distinct values in the array, without getting into 19 loops from 0 to 19 checking against each value!!!
We are using VC++ 6.
Thanks
Adeel
--
|
|
|
|
|
What is the range of your values? If it's not a huge range (more than 0-1000000), you can use a bucket sort technique, which is to basically initialize an array of bools of size 1000000, and set all initial values to false (I'm not sure what values they default to). Then, iterate through all the data in your 2D array and for each value, check if the bool array entry corresponding to the value is true. If it is, then you know you have duplicate values. If it's false, then set the bool array entry to true, so next time, it will detect a duplicate value.
Example: If the current iteration of your 2D array gives you a value of 5, you set boolArray[5] = true.
If you wish to count the values, then you can use an int array instead of a bool array and just increment as you go.
|
|
|
|
|
madeelch1986 wrote: We have 2D array, Data[20][10], it contains some values, want some suggestions on how to count the distinct values in the array
Stealing from Cyrilix, here's one way...
char Data[20][10];
bool Flags[256];
memset(Flags, 0, sizeof(Flags));
int UniqueCount = 0;
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 10; j++)
{
if (false == Flags[(unsigned char)Data[i][j]])
{
Flags[(unsigned char)Data[i][j]] = true;
++UniqueCount;
}
}
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Completely newbie to this site (and Visual C++) so please be gentle if I am doing something wrong.
I am attempting to modify someone else's code and am not sure what I am doing wrong. The project setting indicated "not MFC" and "Win32 debug" which I didn't understand but couldn't find anything in the search. Without changing anything else, I just wanted to add a combo box with a list of items which can be selected. I dropped a combo box control on the dialog form and added 3 items to the data tab and recompile to see if the box displayed properly. The combo box is on the form but nothing is in the drop down list? What might I be doing wrong? I tried creating a new dialog project and the combo box is working fine. Any help would be appreciated.
David
|
|
|
|
|
dkyue92708 wrote: Completely newbie to this site (and Visual C++)
Why are you working on a production project if you are new to C++?
|
|
|
|
|
I am not working on any production project. I work with IP Security cameras and we provide sample C++ SDK to our customer as a courtesy and I am learning to support it. I am taking baby-steps and thought that it would be easy enough to add a simple combo box.
BTW, what would you recommend for me to 'come up to speed' quickly on C++/Visual C++?
|
|
|
|
|
dkyue92708 wrote: BTW, what would you recommend for me to 'come up to speed' quickly on C++/Visual C++?
That's a tough one. Everyone is different. Some people never "come up to speed". What is your background/experience?
|
|
|
|
|
I worked on embedded firmware maintenance for SCSI tape drives for two years using C, then moved to supporting test utilities for the same tape drives using C again. I briefly started learning C++ but seemed to have hard time with the OOP concept so I kinda know enough to be dangerous The trouble is I am in Sales Support now so I don't get to code very often but want to get back into it.
Anyway, do you have any suggestion for my original question as to why the data list for my combo box is not showing up (drop down box is empty)?
|
|
|
|
|
I believe Iain is correct but not having done any GUI stuff without MFC in... well a long time, I am not sure.
|
|
|
|
|
dkyue92708 wrote: "not MFC" and "Win32 debug" which I didn't understand but couldn't find anything in the search.
"not MFC" means just that. The project does not use MFC in its code. "Win32" refers to the target (as opposed to something like ATL) and "debug" means the project is compiled and linked with debugging support. "Release" doesn't include debug stuff like symbol information and optimizes the code.
dkyue92708 wrote: I dropped a combo box control on the dialog form and added 3 items to the data tab and recompile to see if the box displayed properly. The combo box is on the form but nothing is in the drop down list?
Did you actually drop the list down or just assume nothing is in it since nothing is displayed in the visible portion? If the data is there when you do open the drop-list, you need to select an item in your initialization in order to see data in the edit area upon startup.
Judy
|
|
|
|
|
Thanks for the explanation. I need to read more.
On the combo box, I actually clicked on the drop-down arrow and the box opened up but nothing is in it. I drop the same combo box in a new project (MFC AppWizard) and the list does show up. Thanks!
|
|
|
|
|
dkyue92708 wrote: The combo box is on the form but nothing is in the drop down list?
That's because you need to increase the height of the combobox. By default, it's too small.
"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
|
|
|
|
|
Thanks for the feedback but that's not it. I left-click on the combo box control on the form and adjusted the size already. When I click on the drop-down arrow on the form, a drop-down box does appear that is large enough to fit the 3 items I specified in the property data sheet but it is blank.
|
|
|
|
|
With VS6, comboboxes have two separate vertical sizing methods. One sets the height of an unexpanded control, while the other sets the height of an expanded control. If you are using VS200x, I'm not sure how it behaves.
"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
|
|
|
|
|
The items in the data tab are stored as a specific resource type. When a dialog is created using MFC, one of the jobs of CDialog::OnInitDialog is to go looking for this specific resource type, and populate the combo box for you.
It may be in OnCreate (in hindsight I'm pretty sure it is), but that doesn't really change anything here.
As you're not using MFC, no code ever goes looking for the data in the resources to add to your combo box, so it remains empty.
To recap: The data tab in the resource editor is only of use if you're using MFC. You're not.
In your DlgProc for that dialog, you'll need to handle WM_INITDIALOG and add the data there. Whether you hard code the values, read them from string resources, do some digging and write a function to replicate what MFC does is up to you.
Good luck,
Iain.
|
|
|
|
|
Thanks so much for the insightful answer. It makes perfect sense now.
|
|
|
|
|
Hi.
I have to develop an application that it will run in some clients, (3 or 5 PC's) and it connects to a SQL database in a server PC.
I have some skills in MFC:-> and also I know how to connect and query, (also call a SP), a SQL database.
But, my question is:
is that all that I need to know to develop such application?.
I mean, there's something else to know or to care to develop a Client/Server app?.
I need just an orientation about that, maybe an article or something like that.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
For a two-tiered solution (client-RDBMS), that's pretty much all you need. Each client can just
connect to the SQL database server.
If you add a server tier (client-server-RDBMS), then you'd need to add communication between the
clients and that server.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: For a two-tiered solution (client-RDBMS), that's pretty much all you need. Each client can just
connect to the SQL database server.
As long as there are no firewall issues.
|
|
|
|