In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the problems of C++ development tools", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what are the problems with C++ development tools.
1. Application method
Stack: automatically assigned by the system. For example, declare a local variable int b in the function; the system automatically opens up a space Heap for b in the stack: the programmer needs to apply for it and specify the size, in c the malloc function such as p1 = (char *) malloc (10); in C++, use the new operator such as p2 = (char *) malloc (10); but note that p1 and p2 themselves are in the stack.
two。 Response of the system after application
Stack: as long as the remaining space of the stack is larger than the applied space, the system will provide memory for the program, otherwise an exception will be reported that the stack will overflow.
The size of this allocation is recorded at the first address in this memory space, so that the delete statement in the code can release the memory space correctly. In addition, since the size of the found heap node is not necessarily equal to the size of the application, the system will automatically put the excess part back into the free linked list.
3. 2.3 restrictions on the size of applications
Stack: under Windows, a stack is a data structure extended to a low address, a contiguous area of memory. This means that the address at the top of the stack and the capacity of the stack are predetermined by the system. Under WINDOWS, the size of the stack is 2m (or 1m, which is a constant determined at compile time). If the applied space exceeds the remaining space of the stack, overflow will be prompted. Therefore, there is less space that can be obtained from the stack.
Heap: a heap is a data structure that extends to a high address and is a discontiguous area of memory. This is because the system uses linked lists to store free memory addresses, which are naturally discontiguous, and the traversal direction of the linked list is from low address to high address. The size of the heap is limited by effective virtual memory in the computer system. Thus it can be seen that the space obtained by the heap is more flexible and larger.
4. Comparison of application efficiency:
The stack is automatically allocated by the system, and the speed is fast. But programmers can't control it.
Heap is memory allocated by new, which is generally slow and prone to memory fragmentation, but it is the most convenient to use.
In addition, under WINDOWS, the way to allocate memory is to use VirtualAlloc, which is not in the heap, nor in the stack, but directly in the address space of the process, although it is the most inconvenient to use. But it is fast and flexible.
5. Storage in heaps and stacks
Stack: in a function call, the next instruction in the main function (the next executable statement in the function call statement) is the address of the next instruction in the main function, followed by the parameters of the function, which in most C compilers enter the stack from right to left, followed by local variables in the function. Note that static variables are not on the stack. At the end of this function call, the local variable goes off the stack first, then the parameter. The pointer at the top of the stack points to the original address, that is, the next instruction in the main function, and the program continues to run from this point.
An overview of C++ programming language
Master the difference between C++, C# and Java for study
A brief introduction to the functions of C++ development tools
Detailed introduction to the preparation of C++ code examples
How to better build the Visual C++ environment
1. Application method
Stack: automatically assigned by the system. For example, declare a local variable int b in the function; the system automatically opens up a space Heap for b in the stack: the programmer needs to apply for it and specify the size, in c the malloc function such as p1 = (char *) malloc (10); in C++, use the new operator such as p2 = (char *) malloc (10); but note that p1 and p2 themselves are in the stack.
two。 Response of the system after application
Stack: as long as the remaining space of the stack is larger than the applied space, the system will provide memory for the program, otherwise an exception will be reported that the stack will overflow. Heap: first of all, you should know that the operating system has a linked list of free memory addresses. when the system receives an application from the program, it will traverse the linked list to find * nodes whose space is larger than the applied space. then delete the node from the list of idle nodes.
And allocate the space of the node to the program, in addition, for most systems, the size of this allocation will be recorded at the first address in this memory space, so that the delete statement in the code can release the memory space correctly. In addition, since the size of the found heap node is not necessarily equal to the size of the application, the system will automatically put the excess part back into the free linked list.
3.2.3 restrictions on the size of applications
Stack: under Windows, a stack is a data structure extended to a low address, a contiguous area of memory. This means that the address at the top of the stack and the capacity of the stack are predetermined by the system. Under WINDOWS, the size of the stack is 2m (or 1m, which is a constant determined at compile time). If the applied space exceeds the remaining space of the stack, overflow will be prompted. Therefore, there is less space that can be obtained from the stack.
Heap: a heap is a data structure that extends to a high address and is a discontiguous area of memory. This is because the system uses linked lists to store free memory addresses, which are naturally discontiguous, and the traversal direction of the linked list is from low address to high address. The size of the heap is limited by effective virtual memory in the computer system. Thus it can be seen that the space obtained by the heap is more flexible and larger.
4. Comparison of application efficiency:
The stack is automatically allocated by the system, and the speed is fast. But programmers can't control it. Heap is memory allocated by new, which is generally slow and prone to memory fragmentation, but it is the most convenient to use. In addition, under WINDOWS, the way to allocate memory is to use VirtualAlloc, which is not in the heap, nor in the stack, but directly in the address space of the process, although it is the most inconvenient to use. But it is fast and flexible.
5. Storage in heaps and stacks
Stack: in a function call, the next instruction in the main function (the next executable statement in the function call statement) is the address of the next instruction in the main function, followed by the parameters of the function, which in most C compilers enter the stack from right to left, followed by local variables in the function. Note that static variables are not on the stack.
At the end of this function call, the local variable goes off the stack first, then the parameter. The pointer at the top of the stack points to the original address, that is, the next instruction in the main function, and the program continues to run from this point. C++ development tools usually store the size of the heap with one byte in the head of the heap. The details in the heap are arranged by the programmer.
At this point, I believe you have a deeper understanding of "what are the problems with C++ development tools?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.