sanjay.kr.maurya
BAN USERwhere is the link ?
- sanjay.kr.maurya June 27, 2012For me common sense seems to be check the stack size early in function and return with error to avoid further stack usage and help in stack unwinding.
Algo:
call getrlimit to get current stack size
if current size < required stack size then return immediately with error
It can be found through following ways:
1. pointer airthmatic that is take pointer of same type, increment it and get difference between 2 memory addresses.
2. by storing largest value. Assume its integer and try to store number 2^n starting from 0. Compare stored value with original number.
If it is same, icrement number otherwise stop and n is the bit size of this data type.
3. Through shift operation. Intially set variable to -1. Then do right shift untill you getback number equal to 0.
Count how many times you shifted. This is the size of variable in bits.
lets take example
2^10 --> 2^9 * 2 ^1 --> 2^3 * 2^3 * 2^3 * 2^1
Algo:
1. Find nearest square root of power and remainder.
2. Calculate number ^ square root using multiplication and store it. Here 2^3 using multiplication.
3. Again find stored number ^ square root power. Here 2^3 is 8. So get 8 ^3 using multiplication that is 8 *8 *8.
4. Now multiply result with remainder of power. Here it is 512 * 2^1
I'd love it if you have also summarized your logic in algo form.
- sanjay.kr.maurya July 05, 2012