[C++ STL STACK] How to use and what effect it is.
Beta 1.5.0.1: Added the Conduit Power mob effect, which is received when the player activates a conduit. 1.6.0 beta 1.6.0.5: Added the Slow Falling mob effect, obtained by drinking a potion of Slow Falling or being hit by an arrow of Slow Falling. 1.8.0 beta 1.8.0.10: Health Boost and Absorption icons have now changed to look different.
c++_stl_stack.cc
#include<iostream> |
#include<stack> |
usingnamespacestd; |
//1. push |
//2. pop |
//3. emplace |
//4. size |
//5. empty |
//6. top |
//7. swap |
//8. _Get_container |
//s 출력 |
voidprint(deque<int> s) |
{ |
if (s.empty()) |
{ |
cout << '비어있습니다.' << endl; |
return; |
} |
for (int i = 0; i < s.size(); i++) |
cout << s[i] << ''; |
cout << endl; |
} |
intmain() |
{ |
stack<int> s;//스택 생성 |
//1. push |
cout << '1. push' << endl; |
for (int i = 1; i <= 5; i++) |
s.push(i); |
print(s._Get_container()); |
cout << endl; |
//2. pop |
cout << '2. pop' << endl; |
s.pop(); |
print(s._Get_container()); |
cout << endl; |
//3. emplace |
cout << '3. emplace' << endl; |
s.emplace(0); |
print(s._Get_container()); |
cout << endl; |
//4. size |
cout << '4. size' << endl; |
cout << s.size() << endl; |
cout << endl; |
//5. empty |
cout << '5. empty' << endl; |
cout << s.empty() << endl; |
cout << endl; |
//6. top |
cout << '6. top' << endl; |
cout << s.top() << endl; |
cout << endl; |
//7. swap |
cout << '7. swap' << endl; |
stack<int> s2; |
cout << 's : '; |
print(s._Get_container()); |
cout << 's2 : '; |
print(s2._Get_container()); |
cout << 'swap' << endl; |
s.swap(s2); |
cout << 's : '; |
print(s._Get_container()); |
cout << 's2 : '; |
print(s2._Get_container()); |
cout << endl; |
//8. _Get_container |
cout << '8. _Get_container' << endl; |
deque<int> dq = s2._Get_container(); |
print(dq); |
return0; |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
- The stack is a pile of values that is maintained by NSIS. This pile can be as big as you like, so you can put values on the stack, and get values from the stack. There is only one stack. The stack follows the LIFO (Last In First Out) principle. The stack can be used, for example, to pass parameters to functions or plugins.
- The stack effect basically allows air from the lower floor to move up to the upper floors. Here are some of the negative impacts of the stack effect: High humidity – a house with a basement or a crawl space, is known to have increased levels of humidity in this space. Through the stack effect, the high humidity is able to move from the.
A stack overflow is an error that user-mode threads can encounter. There are three possible causes for this error:
- A thread uses the entire stack reserved for it. This is often caused by infinite recursion.
- A thread cannot extend the stack because the page file is maxed out, and therefore no additional pages can be committed to extend the stack.
- A thread cannot extend the stack because the system is within the brief period used to extend the page file.
When a function running on a thread allocates local variables, the variables are put on the thread's call stack. The amount of stack space required by the function could be as large as the sum of the sizes of all the local variables. However, the compiler usually performs optimizations that reduce the stack space required by a function. For example, if two variables are in different scopes, the compiler can use the same stack memory for both of those variables. The compiler might also be able to eliminate some local variables entirely by optimizing calculations.
The amount of optimization is influenced by compiler settings applied at build time. For example, a Debug build and a Release build have different levels of optimization. The amount of stack space required by a function in a Debug build might be larger than the amount of stack space required by that same function in a Release build.
Here is an example of how to debug a stack overflow. In this example, NTSD is running on the same computer as the target application and is redirecting its output to KD on the host computer. See Controlling the User-Mode Debugger from the Kernel Debugger for details.
The first step is see what event caused the debugger to break in:
You can look up exception code 0xC00000FD in ntstatus.h, which can be found in the Microsoft Windows SDK and the Windows Driver Kit (WDK). This exception code is STATUS_STACK_OVERFLOW.
![Stack Stack](https://d3i71xaburhd42.cloudfront.net/37f78a2e17b28d6529928a311d4675a508e6f234/6-Figure6-1.png)
To double-check that the stack overflowed, you can use the k (Display Stack Backtrace) command:
The target thread has broken into COMCTL32!_chkstk, which indicates a stack problem. Now you should investigate the stack usage of the target process. The process has multiple threads, but the important one is the one that caused the overflow, so identify this thread first:
Now you need to investigate thread 2. The period at the left of this line indicates that this is the current thread.
The stack information is contained in the TEB (Thread Environment Block) at 0x7FFDC000. The easiest way to list it is using !teb. However, this requires you to have the proper symbols. For maximum versatility, assume you have no symbols:
To interpret this, you need to look up the definition of the TEB data structure. If you had complete symbols, you could use dt TEB to do this. But in this case, you will need to look at the ntpsapi.h file in the Microsoft Windows SDK. This file contains the following information:
This indicates that the second and third DWORDs in the TEB structure point to the bottom and top of the stack, respectively. In this case, these addresses are 0x00A00000 and 0x009FC000. (The stack grows downward in memory.) You can calculate the stack size using the ? (Evaluate Expression) command:
This shows that the stack size is 16 K. The maximum stack size is stored in the field DeallocationStack. After some calculation, you can determine that this field's offset is 0xE0C.
This shows that the maximum stack size is 256 K, which means more than adequate stack space is left.
Furthermore, this process looks clean -- it is not in an infinite recursion or exceeding its stack space by using excessively large stack-based data structures.
Now break into KD and look at the overall system memory usage with the !vm extension command:
First, look at nonpaged and paged pool usage. Both are well within limits, so these are not the cause of the problem.
Next, look at the number of committed pages: 183528 out of 202280. This is very close to the limit. Although this display does not show this number to be completely at the limit, you should keep in mind that while you are performing user-mode debugging, other processes are running on the system. Each time an NTSD command is executed, these other processes are also allocating and freeing memory. That means you do not know exactly what the memory state was like at the time the stack overflow occurred. Given how close the committed page number is to the limit, it is reasonable to conclude that the page file was used up at some point and this caused the stack overflow.
This is not an uncommon occurrence, and the target application cannot really be faulted for this. If it happens frequently, you may want to consider raising the initial stack commitment for the failing application.
Analyzing a Single Function Call
It can also be useful to find out exactly how much stack space a certain function call is allocating.
To do this, disassemble the first few instructions and look for the instruction
sub esp
number. This moves the stack pointer, effectively reserving number bytes for local data.Effect Stack 1 0 24
Here is an example:
Effect Stack 1 0 2
This shows that Header_Draw allocated 0x58 bytes of stack space.