In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use ListPool". In daily operation, I believe many people have doubts about how to use ListPool. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use ListPool". Next, please follow the editor to study!
What is it
ListPool is a pool of List objects in Unity's UISystem source code, which is extended by ObjectPool. The specific source code is as follows
Using System
Using System.Collections.Generic
Using UnityEngine
Namespace UnityEngine.UI
{
Internal static class ListPool
{
/ / Object pool to avoid allocations.
Private static readonly ObjectPool s_ListPool = new ObjectPool (null, Clear)
Static void Clear (List l) {l.Clear ();}
Public static List Get ()
{
Return s_ListPool.Get ()
}
Public static void Release (List toRelease)
{
S_ListPool.Release (toRelease)
}
}
} Why?
List is a data structure that is often used in games, for example, you need to read form data and load various levels in the level table, and when you need to use List, you need a temporary new, and the subsequent destruction is completely handed over to C #. This approach will lead to unnecessary GC, temporary use of List in the game should consider using ListPool, rather than directly take out a new, List through ListPool to manage.
How?
Called at creation time
List m_Positions = ListPool.Get ()
Called when destroyed
ListPool.Release (m_Positions)
It should be noted that creation and destruction must occur in pairs, otherwise the effect of recycling will be lost.
ListPool inherits from ObjectPool, so the interior is also a Stack (last-in-first-out (LIFO)) LIFO structure. When we need to Get a new List, we first take the first one from the top of the Stack, and when the use is over, release the List (Release), that is, put it back into the Stack heap. In ListPool, when the callback of Get is set to null,Release, the callback is List.Clear () function, leaving List empty.
At this point, the study on "how to use ListPool" 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.