4 ms·
An exe is a singleton, a file is a singleton. Most things in a computer are singletons. We have been battling this OOP problem for decades. Memory mapped st
by 32gbsd 5y ago
An exe is a singleton, a file is a singleton. Most things in a computer are singletons. We have been battling this OOP problem for decades. Memory mapped structure is volitile busy work. There is no perfect design pattern
- nedbat 5y agoI don't know what you mean by "a file is a singleton": I have many files on my computer, and I can open any of them multiple times.
- postalrat 5y agoAnd what happens when all those places you have the file opened want to write or read the file?
- gpderetta 5y agoThey need to use some form if mutual exclusion? Same as for non-singleton objects in a process.
- bdcravens 5y agoIn most cases nothing, the OS or applications will naively read it or write what they believe the current state to be.
- philihp 5y agoYou fclose the handle when you're done, or you create some kind of synchronized semaphore, if you wanna be extra. The issue is really around having multiple handles for writing (not just reading or appending), and the number of times you actually have this problem here is vanishingly rare.
- nedbat 5y agoI'm not saying it's a good idea to open it more than once at the same time, but nothing is preventing me from doing it, so I'm not sure what is meant by, "a file is a singleton"?
- Matthias247 5y agoWhen you start executing a binary, it becomes a procoess. As long as the code in the binary allows for it, there can be multiple instances of it. So a exe/binary is more along of a regular class than a singleton.
- ardit33 5y agoIf two process are modifying the same file.... that file is a 'single object'. So, the Parent's point stays. A process can create its own copy, and do things with it, but eventually it has to load and save it at one single place.
- gpderetta 5y agoThat's exactly the same as a specific non-singleton object instance. Processes have handles that represent open files. The filesystem tree on an unix OS is a better example but that was also been identified as a mistake and there have been attempts to rectify it (namespaces)
- yokaze 5y ago> There is no perfect design pattern There I can certainly agree, but ... > An exe is a singleton, a file is a singleton. Most things in a computer are singletons. I would say you are mistaking the instance for the class. An individual exe/file/... are instances of the abstract concept file or executable. What you are interacting with is usually an instance, not a class.
- 32gbsd 5y agoAnd a singleton is not an instance? Its all the same thing; 1 file, 1 instance. A file has properties, size, data memory, you can copy, paste it, delete it. A file has a type though generic.
- yokaze 5y ago> And a singleton is not an instance? No, a singleton is a pattern that ensures that there is at most a single instance of a class.