当前位置:网站首页>Understanding of singleton mode
Understanding of singleton mode
2022-06-29 09:22:00 【amateur12】
Three private and one public
Private static variables ( Save an instance of the class )
When the function is finished , Static variables do not disappear
Static variables are initialized only once
Private constructor ( Prevent out of class instantiation )
Private clone function ( Prevent objects from being generated by cloning )
Public static methods ( Usually named getInstance), Returns a reference to a unique instance ( Calling this class is equivalent to an interface )
The solution is how to create a unique object instance in the whole project
Make sure that a class has at most one instance , And provide a global access point
It does not create instance copies , Instead, a reference is returned to the instance stored inside the singleton class
Because every time you open and close the database, it is a great test and waste to the database
advantage :
Avoid excessive new Operation consumes a lot of resources , Solve memory overhead
Some configuration information can be controlled globally through a class
You can also look at the code
There are two types : Hungry and lazy
Hungry Chinese style : The class was created when the instance was loaded , Waiting to be used by program
Slacker type : Create the singleton class object only when you really need to use it
How does lazy style ensure that only one object is created
Double Check( Double check ) + Lock( Lock )
If the object is not instantiated, lock to create , If you have instantiated , There is no need to lock , Get the instance directly
The choice of hungry and lazy
If the memory requirements are not high during development , Use the hungry Chinese style , Because it's easy to make mistakes , And there are no concurrent security and performance issues
If the memory requirements are very high , So use the lazy way , You can create the object at a specific time
边栏推荐
- Summary of 3DMAX jamming, white screen and rendering crash
- UE4 编译单个文件(VS与编辑器分别启动)
- Iso16000-9 testing of volatile organic compounds in building products and furniture
- ActiveMQ message component publish subscribe redelivery message redelivery
- Network security issues
- promise方法的简单使用
- AugFPN:改进多尺度特征学习用于目标检测
- 训练查看(问题暂存)
- jar包和war包
- Remember to customize the top navigation bar of wechat applet
猜你喜欢

Summary of IO streams

Augfpn: improved multiscale feature learning for target detection

Record the field name dynamically modified by SetData of wechat applet

AugFPN:改進多尺度特征學習用於目標檢測

YOLO Nano:一种高度紧凑的只看一次的卷积神经网络用于目标检测

实例报错IOPub data rate exceeded

H5 soft keyboard problem

train_on_batch保存一下loss函数变化的图像

H5软键盘问题

UE4 动画重定向
随机推荐
【To .NET】C#数据模型,从Entity Framework Core到LINQ
Verilog data type
Debugging H5 page -weinre and spy debugger real machine debugging
LFFD:一种用于边缘检测的轻量化快速人脸检测器
Let's make a summary
MySQL uses union all to count the total number of combinations of multiple tables and the number of tables respectively
Member inner class, static inner class, local inner class
PAT (Basic Level) Practice (中文)1003 我要通过! (20分) C语言实现
[to.Net] C data model, from Entity Framework core to LINQ
Verilog size and +: Using
H5软键盘问题
Ue4 installe le plug - in datasmith dans la version 4.20-23
General multiplier design, verilog code
Wechat applet sharing page, sharing to the circle of friends
训练查看(问题暂存)
Open3d farthest point sampling (FPS)
Research progress of target detection in the era of deep convolutional neural network
Instance error iopub data rate exceeded
SSD改進CFENet
Wechat applet sub components transfer values to the page (communication between parent and child components) with source code