In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the use of lua gc". In the daily operation, I believe that many people have doubts about the use of lua gc. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the use of lua gc. Next, please follow the editor to study!
Mainstream garbage collection is generally based on reference counting and tag removal algorithms.
In terms of memory usage, reference counting undoubtedly has an advantage. When the reference count is 0, the corresponding objects will be cleared directly. A typical application is C++ 's smart pointer. But gc based on reference counting has a disadvantage that it cannot solve the problem of circular references. If A referencing B causes B's reference count to be + 1, B's reference A will also cause A's reference count to be + 1, so that the AMagi B object will never be deleted. Remember that weak references seem to be used in OC to solve this problem, but it always feels like a hole in the code.
The clearly marked algorithm can perfectly solve the circular reference problem by traversing all reachable pointers from the root and then reclaiming the unreachable areas. In this way, even if An and B loop references, but there are no other objects to reference An and B, then An and B objects are unreachable. At this point, An and B objects can be deleted. However, the tag removal algorithm has a fatal flaw, that is, it needs to pause the whole program for mark-sweep when gc.
Recently, I took some time to study the go language. Sure enough, it may be because I am too young. Go also has this problem. When searching for information, we find that many people are complaining about the gc part of go. The main application area of go is the server part. However, it is said that the gc of go will cause an unpredictable pause, which is very fatal to the server.
Seeing this, I am suddenly very worried that lua also has this problem, and the upper logic is written in lua in silly, and I am very worried about whether the gc in lua will also cause stop-the-world. So I found the manual and read it again, and found that the way lua's gc worked was taken for granted, resulting in the misuse of lua.
The gc algorithm in lua adopts incremental tag removal algorithm, which allocates the complete gc time to each step by executing one small step at a time, which improves the real-time performance of the whole program. (exactly how to do it, we will not know until after reading the source code: d)
In lua is divided into manual gc and automatic gc.
The operation mode of automatic gc is controlled by setting the intermittent rate of garbage collector and the step rate of garbage collector.
Under some special conditions, if we need to manually control the timing of gc, we can LUA_GCSTOP to stop the automatic garbage collector. Then manually call LUA_GCSTEP at the right time to initiate an incremental garbage collection.
In this way, at least in gc's strategy, lua should do better than go. Of course, the specific situation still has to wait to see the implementation before a more accurate comparison.
Btw, as a modern language, gc has been an indispensable part. However, the problem with gc is that it doesn't realize the problem at all when developing, and all kinds of situations may occur in front of a large amount of data. Therefore, to be familiar with a language is not only to be familiar with its grammar, but also to have a deep understanding of the Gc mechanism of the language.
At this point, the study of "how to use lua gc" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.