Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Optimisation challenges
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jun 16, 2010 5:37 am    Post subject: Reply with quote

If I can't use inline asm can I write all the opcodes manually

or what if I only use intrinsics.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Jun 16, 2010 5:56 am    Post subject: Reply with quote

Burningmace wrote:
Deltron Z wrote:
I can't belive what I'm hearing! Shocked
Recurrsion sucks? well, in mathematics, any recurrsion can be defined pretty easily without a recurrsion too, but it computer programming this isn't the case.


Recursion, whilst useful, is a bad idea in programming. It only takes an unexpected input value to cause your whole program to crash. You also have to remember that the "default stack size" is not a defined value, so if another person were to compile your code on another compiler it may fail.

Slugsnack wrote:
We're allowed to code the whole thing in inline assembly ? Lol

Never thought of that one. Ok, new rule - you cannot use inline ASM. I'll update the rules appropriately.

You're terribely wrong!!!
Recurrsion is a bad idea? kinda laughed there for a second I most programs, ever, use recurrsion. 3D games untill console-based tic-tac-toe or mine-sweeper. from big compilers until the simplest calculators. your own operating system uses recurrsion to search through files! most of the mathematical functions in math.h are recurrsive!

AND NO, recurrsion DOES NOT "takes an unexpected input value to cause your whole program to crash", that's just bullshit! recurrsion takes expected values that result in another expected value! no random, unexpected behaviour unless you've let a monkey write a random code in recurrsion.
Let's take pow function for example - accepts 2, return 4. no crash, 2 is expected as it is the input and 4 is expected as it is the desired output.
And why is C++ the only language? I wrong mine in C, not C++. Rolling Eyes and ASM would be just fine for these, it's not like you've asked them to write thousands of lines of code, just a simple function.
Back to top
View user's profile Send private message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Wed Jun 16, 2010 6:03 am    Post subject: Reply with quote

Plain C++ only please, slugsnack. Wink

Deltron Z wrote:
Recurrsion is a bad idea? kinda laughed there for a second I most programs, ever, use recurrsion. 3D games untill console-based tic-tac-toe or mine-sweeper. from big compilers until the simplest calculators. your own operating system uses recurrsion to search through files! most of the mathematical functions in math.h are recurrsive!


It's recursion, firstly. And it *is* a bad idea in programming. It's a useful thing to have in terms of mathematics, in fact it's completely necessary, but standard recursion in the stack is bad. Just to be 100% clear, this is what I'm defining as recursion:
Code:
int someFunction(int number)
{
    // do something here first
    return someFunction(someValue);
}


It is a simple procedure to unwrap the recursion into a loop with a state:

Code:
int state = 0;
while(<cond>)
{
    state = someFunction(state);
}


It's just as quick, and doesn't rape your stack.

_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 16, 2010 7:42 am    Post subject: Reply with quote

You should not dismiss recursion as inherently bad because it is not. There are cases when recursive code is a lot easier to write or a lot easier to read. Sometimes readability means more than efficiency. Increasing the efficiency by 10% on a non-speed critical part of a program but compromising the ease of development and productivity of all developers to look at your code in future is not a good tradeoff for example. For example, take a binary search tree. The code to traverse it and add an element recursively is trivial but it gets more complicated and would take you longer to solve as an iterative problem.

Yes, recursive functions do TEND TO BE less efficient because you have the CALL overhead as well as a stack which increases more and more. It is silly to say that non-sanitized input will cause it to randomly crash because that is simply not true. It is true in the same way that is true of any program. If the programmer does not handle these inputs, yes it would crash. A lot of the time input bound checking is checked as a wrapper to a recursive function. It is not sensible to do it within it because it means the input is checked on each iteration. It tends to be faster to do things all in 1 go. Stack overflow can be avoided pre-emptively by knowing what bounds your input is going to take and setting an appropriate stack size in your linker options.

Anything that can be done recursively can be done iteratively by replacing the function call with a 'while' loop and making basecase conditions 'break'. Also one of you two mentioned STL earlier in a context which was completely irrelevant to the points you were arguing. The STL stack is unrelated to the program stack other than that it might use it. But its implementation details are abstracted from the user of it anyway. STL stack is simply a container/abstract data type.
Back to top
View user's profile Send private message
Uzeil
Moderator
Reputation: 6

Joined: 21 Oct 2006
Posts: 2411

PostPosted: Wed Jun 16, 2010 8:07 am    Post subject: Reply with quote

It isn't true that you can just change a recursion to a while and throw some breaks in there. In many of the cases where recursion is a good idea, it would be necessary to set up dynamic-length arrays left and right in a non-recursive formula, and wind up taking much more processing time(and sometimes more memory anyway) than a recursive algorithm would've.

Especially for someone who is trying to challenge others to create the 'most optimized' (debatable, considering the difference between readability, binary size, processing time, and the difference in processing time from different amount of data.), this should be understood.

Don't be stubborn just because you originally spoke out against it =S You're being told plenty of good advice, learn from it.

_________________


Mini Engine v3.0
Mipla v1.0

Reposted old threads out of the MS section.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Jun 16, 2010 8:13 am    Post subject: Reply with quote

Burningmace, what you said is just stupid!
"Rape your stack"?! and what do you think recursion does after it returns? it empties the stack. not only that, better than having an array and a loop - it's more like having a list and a loop - once the memory is no longer needed it is removed from the stack, and this way we can calculate bilions of different combinations (where a combination could take, let's say, 1KB) of, let's say, returning change with different coins. you don't have enough memory to do so with just an array becuase you don't have enough memory.
I'd like to see you beat 3-lines recursion with a loop and an array. can you make it more efficient? efficient would be short in code (a few lines, compared to 3-lines recursion), in memory (can you make an iterative code that uses the same amount of memory to your disposle to do the same thing a recursion does? using a list as I mentioned would basically turn it to something like recursion because you will basically do the exact same process as recursion... so - no lists too, because anything like recursion sucks!!! right?) and in speed. (run under a second)

I didn't even read Slugsnack's and Uzeil's comments yet, because you are too ignorant to admit you were wrong one time and learn a lot from other people's experience.
So, as I said before - just know this: every technology you use and love so much (Computers, TV, Cellphones, Calculators...) uses recursion half of the time.
I think you're just ashamed that you can't understand recursion so you're trying to prove it "sucks"... for your information: there is no place in the world that would even think of hiring someone that can't use recursion (or think it sucks), I bet most of these places would laugh in your face hard... I hope you've got other hobbies. Confused

Edit: I forgot to mention, not only that it's not a problem to tell people to simply change the stack size manually - it can be done by code. (See #pragma directives...)


Last edited by Deltron Z on Wed Jun 16, 2010 8:21 am; edited 1 time in total
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 16, 2010 8:19 am    Post subject: Reply with quote

Deltron Z : I think you may be a little confused here. What he means by rape the stack is that during the execution of the recursion the stack grows by many many factors due to it being extended for parameters + return addresses on every single call. That does not even take into account any local variables each call uses either. Also the stack is actually memory..
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Jun 16, 2010 8:24 am    Post subject: Reply with quote

You misunderstood me - I know that - what I meant is that everytime you return they are also being removed from the stack. so, you can't say it just gets filled because it also takes care of emptying at the same rate it fills it, there's no way the stack would be filled in 1KB and release only 512 bytes... it's just that removing these bytes from the stack might occur in different times, like 10 calls, 1 return, 20 calls and 29 returns. no problem with that.
Back to top
View user's profile Send private message
Uzeil
Moderator
Reputation: 6

Joined: 21 Oct 2006
Posts: 2411

PostPosted: Wed Jun 16, 2010 8:25 am    Post subject: Reply with quote

The last sentence of slugsnack's being the important part, Deltron. While recursion can, in the right circumstances, get more speed, more readability, and even use less memory: a limitation it has(that you spoke the opposite of) is that it's bound by the memory your linker and operating system grant to running applications. Non-recursive loops have the added benefit that, if absolutely necessary, they can sacrifice speed(hugely) and use file io to expand their data size cap by the hundreds.


(Not that I want to, in any way, make it seem like the 'no recursion!' side is reasonable. At all.)

_________________


Mini Engine v3.0
Mipla v1.0

Reposted old threads out of the MS section.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 16, 2010 8:33 am    Post subject: Reply with quote

A little extra info for interest. The stack is simply a block of memory that is defined by the program for specific use, ie. as the stack. Its main use is parameter passing and local variables. Now the interesting bit. The stack is actually extendable and can grow. If on a heavily recursive app, the stack commit size is exceeded, the next probe triggers a guard-page exception which causes the stack to extend and the guard page to increment to the next page.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Jun 16, 2010 8:34 am    Post subject: Reply with quote

Ofcourse not every function should be recursive - it should be when it is needed!
Other than that, trust me, the operating system have more than enough spare memory for our disposle so we can create massive recursions with no problems at all.

You might want to take a look, for example, at [url=http://projecteuler.net/index.php?section=problems&id=15]Problem 15[/b] at Project Euler. notice there are (40!)/(20!20!) = 137,846,528,820 possiblities! personally, I solved this one in recursion. (it can be as easily and perhaps even more easily solved with loops, but that's not the point) and it didn't even tickle my computer's RAM nor CPU... Assuming we pass 4 bytes for the return address and 8 more bytes parameters, a total of 12 bytes. 137 billion * 12 = 1.644 trillion! that's 1.644 TeraBytes, 1644 Giga Bytes, 1644000 Mega Bytes!
You must understand it releases the memory too! obviously you can't allocate nearly 2 Tera Bytes on today's computers...

Edit: a quick look at the stickies...
Quote:
Many modern high-level computer
languages can handle recursive constructs directly, and when this is so, the programmer’s job may be
considerably simplified.

http://www.math.upenn.edu/~wilf/AlgoComp.pdf

Chapter 2 - read.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 16, 2010 8:54 am    Post subject: Reply with quote

You realise just because it has that many permutations/combinations it does not mean you went through all of them. You just kept going till it stopped. Also it's likely your algo worked such that it never held that much all at once. Given each program only has a userspace region from 0x00000000 to 0x7fffffff and a specific sections of that are not usable as heap/stack memory ( eg. space needed for pe headers, minimum application address not starting from 0x00000000, etc. ) it is not possible you used 1644GB without writing to disk. 'Trust me', virtual memory is an abstraction such that each program thinks they have more memory.. but not that much.

http://en.wikipedia.org/wiki/Virtual_memory

That page - read.
Back to top
View user's profile Send private message
Uzeil
Moderator
Reputation: 6

Joined: 21 Oct 2006
Posts: 2411

PostPosted: Wed Jun 16, 2010 9:00 am    Post subject: Reply with quote

Right, neither of us are saying that a recursion can't, by the time it's done, handle massive loads of memory. What the limitation here is that it can't hold as much at one time as non-recursive methods can, simply because of the additional options given to them using hard disk space. The reason I mentioned 'operating system' is just that some operating systems allow RAM to leak loads into the hard disk space(some more than others, some let you choose how much, etc).

And if you were replying to me on the "Ofcourse not every function should be recursive - it should be when it is needed!" -- I just put that bit in what I said for correctness.

_________________


Mini Engine v3.0
Mipla v1.0

Reposted old threads out of the MS section.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Wed Jun 16, 2010 9:03 am    Post subject: Reply with quote

Ofcourse I did not use 1644GB - not at all... again you are misunderstanding me, I guess my English is too poor or I'm just explaining too bad.
What I was saying is that the total memory needed to calculate all the combinations is about 1 Tera Byte, alright? now, once one combination was found, since the function was recursive, it returned and thus released 8 bytes. next, it tried the other direction and there I've got another path, and still having a path of size 40 steps, assuming each step takes 8 bytes to reresent than it took 320 bytes at most at all times. you understand? once it reached the end, it only used 320 bytes to represent a combination, however it released the memory, then the memory released is free for another combination representation to use.
So, after getting a certain path with last step being both right and down, I can now return twice (and free 16 bytes) to generate the next path, down and then right and down again. once I'm done, I return once again (24 bytes) and then instead of last combinations begin right, x, x it would be down, x, x, so I have calculated path where the last steps are right, right, right and also right, right, down and right, down, right and right, down, down. now I have to calculate down, right, right, then down, right, down and so on... I don't have to explain. Wink
So I just showed how I used 320 bytes to find all paths which is in total 1 tera byte in size.

I hope this clarifies everything! Smile
I'm tired of explaining myself over and over... I get misunderstood a lot lately. Confused maybe I just use bad examples...
Back to top
View user's profile Send private message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Wed Jun 16, 2010 10:29 am    Post subject: Reply with quote

Deltron Z wrote:
I think you're just ashamed that you can't understand recursion so you're trying to prove it "sucks"... for your information: there is no place in the world that would even think of hiring someone that can't use recursion (or think it sucks), I bet most of these places would laugh in your face hard... I hope you've got other hobbies.


I'm going to chalk this down to your inability to argue your point without resorting to personal attacks. In future it would probably be prudent to argue less vehemently, 'lest ye be dealt with'. One can get by without recursion, and I'm actually sat at work now discussing this with a collegue. His exact words were "meh, I'm not a fan but I'll use it if it's gonna save me some work".

I accept that there are times where recursion may be favoured because of readability, and perhaps I have been misinformed as to the performance and stability benefits of converting recursion to iteration. I have always been taught from square one that recursion is a difficult beast, and that it is best to be avoided except where absolutely necessary.

If a base condition is not met early enough, the stack might overflow in certain circumstances. The maximum stack size is not a single defined value, and thus is unpredictable. In an open source scenario, one would expect to have the code compiled on multiple architectures with multiple compilers. Whilst GCC might default to 8MB of stack space, another compiler might choose 1MB or 2MB. This could cause problems and be difficult to trace since the number of previous calls on the stack as well as the input value(s) to the recursive function would alter behaviour. I personally prefer to keep such things out of my code, but that is my personal choice.

My apologies if I seemed confrontational, but I have a point to make and it is difficult to do so in a calm and objective manner when I am talking to someone whose temper is easily inflamed.

All pleasantries aside, can we get back on topic? Smile

_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites