Hi.
Aaron here. When working on Traders of Known Space free version I hit the stack limit a couple of times by accidentally creating a loop where the function I called ended up in a round-about manner calling the function that called it in the first place. Oopsy. Lol. The thing for one to keep in mind is the stack is only being added on to when functions already on the stack are making calls to functions, be them already in the stack or not yet being used, they get added on the top. But if a function calls 10 functions, and those functions all explicitly return or just achieve a return by running out of statements, then the function that called those 10 will also be killed, provided those 10 functions were actually the last of what the function was to do.

It's like a tree branch. If your tree has a branch on it which heads off in a northerly direction, and stretches on and on with knots along it to represent function calls, and it grows so long that it starts to overpower the tree. Eventually the branch would break, let's figuratively say that would happen at 10000 knots, or what ever you use to represent the whole thing. But if our theoretical code finishes somewhere before it gets to 10000, and never grew the branch that long, the tree would be ok. Function calls usually create another branch that is more or less attached somewhere on the original branch, not the trrunk. So if you finish with any of the little, or big, branches that go off the original branch, you pretty much end up on that big primary branch again. Once your code finishes what it's doing, I like to analyze that branches break off, helping to keep your branch a manageable length. As long as you don't let any main branch with all it's own branches actually end up a distance of 10000 away from the trunk, and correct me if I'm wrong but you can have up to that amount for each branch that actually starts on the trunk of the proverbial tree.

Again, explicit returns help to bring things under control, but just running out of tasks for a function to do, which is just a void, will do the same thing so don't let that confuse either. But at the same time, if a function calls another function that runs for a while, the function that called it is still running. This is because when just using function calls to one another like that, the code won't continue running on the calling function until the called code finishes what it's supposed to do.

Analogy alert...
If I'm this function, and I ask you to go get me a bottle of pop. You're the goget function. I've called the goget function. Now since I'm a function I can't do anything while I wait for you to bring me back my pop because you are the one being processed now. So I sit there frozen in time until you "return" my pop for me or else fail to do so release the program of your attention, where by I would immediately become unfrozen and go on about my marry way. However, if you had to ask someone else to pour the pop into a cup, and still someone else to put ice in that cup too, and then still someone else to bring it back to me. I would remain frozen, and so would you while each of your orders were carried out, so me and you would both be frozen until your orders were completely handled, either successfully or not. Once your ordered people functions finished their jobs, either successfully or not, the program would then start to listen to you again. But you carried out what you were supposed to do, all be it by having someone else bring me my pop, so maybe you've reached the end of your task, so the goget function is ended, and so I'm now the only function in the call stack, theoretically.

hth and please correct me if I mix anything up










On 8/30/2014 10:39 PM, Thomas Ward wrote:
Hi Nicol,

Quite simply put the call stack also known as the control stack or
simply the stack is the way your memory is structured. Computer
programs push the address for a function or a variable onto the stack,
stacking them up like blocks, and when a function returns it pulls the
address off the stack and hands control over to that memory address.
Its a complicated subject and I know of know way to discuss this in
layman terms without using a lot of technical terminology likely to be
unfamiliar to you.

In any case a game or any program can have far more than 10,000
functions imbedded in the program. The issue is not how many functions
you have, but how many are being piled onto the stack at any given
time and are actively being used. I know of no one who actually has
literally 10,000 functions running all at once. Most will return
freeing up the stack so unless someone is purposely trying to create a
major memory leak or is utterly incompetent that won't likely happen.

However, in the event you used up the entire stack available to you
would get what is known as a stack overflow. In short you run out of
available memory addresses to store information and the system
crashes. A truly ugly situation, but I don't see anyone doing that
with BGT unless they intentionally do so.

If a person is following standard programming principles there should
not be any serious danger of increasing the size of the stack. After
all most computers have a lot of memory to work with and if the person
is certain to clean up the memory when they are done with global
variables, exit functions properly, dispose of objects, etc there
isn't anything to really worry about. They should never run out of
memory to begin with to cause a stack overflow.

Cheers!


On 8/30/14, Nicol <nicoljaco...@telkomsa.net> wrote:
What is a call stack?
And what will happen if a game have more than 10000 functions?
Will it take up too much CPU and memory?
Is there any real danger if the call stack is increasing a lot?
Unfortunately I do not have a solution for you as I am a very beginner with
bgt  myself.
But this call stack subject  sounds interesting .
What I know as a beginner is that large programs take up more cpu and
memory
than small programs.
With my very limited knowledge of the functioning of software I'd say as
long as the code does not take up lots of cpu and memory you can go
adventurous and have more than 10000 functions.
Others with better knowledge of programming may correct me.

On 8/29/14, john <jpcarnemo...@gmail.com> wrote:
HI all,
        As the subject suggests, I'm wondering if its possible to clear (or
increase the size of) the call stack in bgt (or any programming
language, for that matter). I'm having difficulty from keeping my
projects from continually increasing the size of the stack, and while
this would be just fine for a small program, I'm pretty sure my major
project is going to go over 10000 eventually, possibly regardless of
how perfectly the player performs. If there's no way to do this, are
there any tips I can get as to how to make a program continue running
without increasing the call stack, as I'm going to have to be
constantly switching between functions, that need to be able to call
each other a theoretically infinite number of times.

---
Gamers mailing list __ Gamers@audyssey.org If you want to leave the
list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the
list, please send E-mail to gamers-ow...@audyssey.org.

---
Gamers mailing list __ Gamers@audyssey.org If you want to leave the list,
send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.


---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to
gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to