Nicholas Ring Yes, usually it is, especially if you hide the variable in the implementation, and only expose the function, then you get a lazy-initialized singleton.
The exception is probably when that singleton is going to be used in a multi-threaded environment, as then lazy-initialization needs to be protected by critical section or locks, while an instance created in the initialization section doesn't need them.
Anthony Frazier When it comes to the VCL, it isn't always a great example to follow. :)
ReplyDeleteNo, not always.
ReplyDeleteNicholas Ring Yes, usually it is, especially if you hide the variable in the implementation, and only expose the function, then you get a lazy-initialized singleton.
ReplyDeleteThe exception is probably when that singleton is going to be used in a multi-threaded environment, as then lazy-initialization needs to be protected by critical section or locks, while an instance created in the initialization section doesn't need them.