Quote (Canadian_Man @ Oct 18 2018 09:31am)
I’m learning, and I’m a bit stuck on this concept. I’m using VBA currently, though I’ll be picking up other languages soon (C#, Python, and/or idk yet). The language is inconsequential to my question, this is more conceptual.
Let’s say I’m using SQL as my database for saving long term.
Let’s say I want to store a bunch of objects in global memory, and keep them in memory until the program is closed. Some might have dictionaries in them, some might have arrays or other objects, etc.
I’m confused about how in programming I would go about this. I know it depends, but I need some guidance on some of my options.
So far, these are the solutions I know of:
1) Recall what I want from SQL directly every time I want it.
2) Create a singleton class with a global list or collection stored inside it. Instantiate that global object when the program starts, and then store what I want within that.
any help is much appreciated
I'd use SQLite not sure what "I'm using SQL as my database" mysql? sqlite3? postgresql? mariadb?
Quote (Klexmoo @ Oct 18 2018 02:40pm)
All you need to do is keep whatever objects you need stored in a list, and then save that list to a file either as JSON, XML, Binary or just storing the values directly in a database before your program closes.
You don't need to create a class with a list you access. Where to put the list depends on what you want to do, and whether using a list is even the right choice also depends on your specific use case.
I would suggest going the route of using an SQL server or just using SQlite as that's as simple as it gets, and I doubt you _need_ in-memory storage of the objects at all times.
Yea he can actually use SQLite's :memory: database which is a database in the memory. It's very easy to use, will not persist through reboot. you can dump it to file or just use an on file db.