What is the best way to create and use a struct with only one instantiation in the system? Yes, this is necessary, it is the OpenGL subsystem, and making multiple copies of this and passing it around everywhere would add confusion, rather than relieve it.
The singleton needs to be as efficient as possible. It doesn't seem possible to store an arbitrary object on the static area, as it contains a Vec with a destructor. The second option is to store an (unsafe) pointer on the static area, pointing to a heap allocated singleton. What is the most convenient and safest way to do this, while keeping syntax terse?
https://stackoverflow.com/questions/27791532/how-do-i-create-a-global-mutable-singleton
我想到的就是比如连接数据的client,比较重。
【 在 st123123 的大作中提到: 】
: 具体什么场景用singleton?
--
FROM 114.249.21.*