In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of Go language memory escape, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain something after reading this Go language memory escape article, let's take a look.
We learned some astrophysics in high school, such as the three common cosmic speeds:
First cosmic speed: the minimum speed at which a spacecraft escapes from the ground and moves around the earth in a circle: 7.9km/s
Second cosmic speed: the minimum speed at which a spacecraft can escape from the earth: 11.18km/s
The third cosmic speed: the minimum speed at which a spacecraft escapes from the solar system: 16.64km/s
Now that we understand the escape behavior of spacecraft, let's do something special today: memory escape.
Through this article, you will learn the following:
Memory layout and Stack of Cstroke +
Memory Escape and Escape Analysis of Go
Summary of memory escape
Memory layout and stack of Part1C/C++
This should be an interview question that appears very frequently.
As a static strongly typed language, after compiling into binary files, the memory space of the whole program at run time is divided into:
Kernel space Kernel Space
User space User Space
Kernel space mainly stores some control information when the process is running, while user space stores some information about the program itself. Let's take a look at the layout of user space:
The main features of heaps and stacks:
Stack area (Stack): automatically allocated and released by the compiler, storing function parameter values, local variable values, etc., but the space is generally smaller than the KB~ number MB
Heap area (Heap): there is no GC mechanism in CCompact +. Heap memory is generally applied and released by programmers. The space is large, and whether it can be used well depends on the level of the user.
Go language has a deep relationship with C language, and Go will also face the problems faced by C language, such as the memory allocation of variables.
In C language, programmers need to decide whether to use heap or stack according to their own needs. OS is fully responsible for stack memory, but heap memory needs to explicitly call functions such as malloc/new to request, and corresponding to call free/delete to release.
The Go language has a garbage collection Garbage Collection mechanism for heap memory management, and there are no keywords for heap memory allocation like malloc/new.
The overhead of allocating and releasing stack memory is very small, and heap memory is much more expensive for Go than stack memory.
Memory Escape and Escape Analysis of Part2Go
If you have ever written CUniverse +, you will know that a local variable is declared inside the function, and then its pointer is returned. If an external call is made, an error will be reported:
# include using namespace std; int* getValue () {int val = 10086; return & val;} int main () {cout
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.