we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack. in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ?? if yes how can we avoid ??
here we have no choice other than subroutine.. 4 1730
asit said:
we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack.
We don't actually know that, because the C Standard doesn't guarantee it,
but it is certainly true that some systems work in that way.
in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ??
It's unlikely. If you're sorting a million items in a recursive O(n log n)
algorithm, you're unlikely to have to recurse more than twenty calls deep,
and that's really no big deal. (2^20 == 1048576)
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
then what is the best recursion procedure..if we have to sort a
million integers
asit said:
then what is the best recursion procedure..if we have to sort a
million integers
It depends on the range of the integers. For example, if the inputs were
all in the range 0 to 9 - single digits - I would give one answer, and if
the inputs were bignums of arbitrary length, I'd give a very different
answer. And if, as is likely, the truth is somewhere between those two
outliers, I'd give a different answer again.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
asit wrote:
we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack.
We know (note spelling) no such thing. There are many ways for
subroutines to be supplied with the location to which returns should
lead, and many ways for subroutines to use such information.
Any question based upon your false premise is useless. However,
in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ?? if yes how can we avoid ??
Unless you somehow have access to an infinite memory machine, it is
obvious that any unrestrained use of a stack carries with it the chance
of overflowing that stack. It doesn't matter what use you put that
stack to. There is no automatic way of avoiding violating the limits of
any region of memory. As to which precautions you should take, that
is obviously intimately bound to your implementation. Knowledge of your
implementation and the skills to use that knowledge have nothing to do
with the C programming language and are off-topic in <news:comp.lang .c> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ip4ram |
last post by:
I am quite puzzled by the stack overflow which I am encountering.Here
is the pseudocode
//define stack structure
//function operating on stack
void my_stack_function( function parameters)
{
do required stuff
if(some conditions obeyed)
|
by: Aguilar, James |
last post by:
Hello all,
To begin, yes, this -is- a homework assignment. However, it is for my
Algorithms class, and my instructor has given us explicit permission to use
"expert" groups like newsgroups, so if that's your only reason not to help,
please do. Otherwise, I guess it's OK. But, just remember, I'm not asking
you to do my work for me, just to point out my error.
My problem is not with the algorithm itself (standard divide and conquer on...
|
by: Jim |
last post by:
I have spent the past few weeks designing a database for my company.
The problem is I have started running into what I believe are stack
overflow problems. There are two tab controls on the form (nested),
three list views, one tree control with up to 30,000 nodes, maybe 15
comboboxes (half of which have a large recordset as rowsource), 20 or
so buttons and around 30 text boxes (not to mention the images,
labels, etc and around 1000 lines...
|
by: Victor |
last post by:
Hello,
I've got a situation in which the number of (valid) recursive calls I
make will cause stack overflow. I can use getrlimit (and setrlimit)
to test (and set) my current stack size. However, it is not as
straightforward to determine the base address for my stack space. The
approach I have taken is to save the address of an automatic variable
in main( ), and assume this is a fairly good indicator of my base
address. Then, I can...
|
by: David W. Walker |
last post by:
I am attempting to port a C code that runs OK on a number of Linux and Unix
machines to Windows XP using Visual Studio C++. I have set the program up as
a console application, but when I try to run it I get a stack overflow:
Unhandled exception at 0x0041e715 in NewMD.exe: 0xC00000FD: Stack overflow.
The call stack is:
NewMD.exe!_chkstk() Line 91
NewMD.exe!mainCRTStartup() Line 259 +0x19
| |
by: Daz |
last post by:
Hi everyone!
It is indeed, once again time for me to ask another stupid question.
I have been searching around on the net for quite a while, and can't
find anything that explains 'exactly' what a stack overflow is, or how
it's detected. I know that it's leterally putting too many objects on
the stack, but how many objects can you have on the stack, or do OSs
only allow a certain number of recursive calls to functions?
|
by: John |
last post by:
I know this is a very fundamental question. I am still quite confused
if the program call stack stack should always grows upwards from the
bottom, or the opposite, or doesn't matter??
That means the stack pointer should go upwards when there are "push"
operations,
and stack pointer should go downards when there are "pop" operations??
If this is the case, the address should go upwards (increasing) or
downards (decreasing) then? i.e....
|
by: amit.atray |
last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc)
having some Old C-Code (ansi + KR Style) and code inspection shows
some big size variable (auto) allocated (on stack)
say for ex.
char a;
(this type of code and other complex mallc/free etc is used frequently
and total approx 450 files, each file is of approx/avg 1000 line,
|
by: CJ |
last post by:
Hello:
We know that C programs are often vulnerable to buffer overflows which
overwrite the stack.
But my question is: Why does C insist on storing local variables on the
stack in the first place?
I can see two definite disadvantages with this:
1) deeply nested recursive calls to a function (especially if it defines
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |