Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Plugins
➜ Json vs. Serialize
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Rene
(46 posts) Bio
|
| Date
| Thu 28 Jun 2018 09:43 PM (UTC) |
| Message
| I've seen no newer plugins using json.encode to save tables instead of serialize, is there a benefit or difference between the two methods?
Is there a speed difference?
Thanks. | | Top |
|
| Posted by
| Fiendish
USA (2,541 posts) Bio
Global Moderator |
| Date
| Reply #1 on Fri 29 Jun 2018 05:38 AM (UTC) Amended on Fri 29 Jun 2018 05:39 AM (UTC) by Fiendish
|
| Message
| | That's an interesting question. If there is a speed difference, I can't imagine a scenario where it would be enough to matter. |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Fri 29 Jun 2018 10:00 PM (UTC) |
| Message
| The encoding of both Lua serializing and Json serializing is done in Lua, so they would be comparable speeds.
The decoding of Lua is done in C (by the Lua engine) however the decoding of Json is done in Lua (using the LPEG module) so that would probably be slightly slower.
If you are using large enough amounts of data that speed is an issue, you might want to use an SQLite3 database instead. That is what I did for the mapper module which had to store data about thousands of rooms. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Rene
(46 posts) Bio
|
| Date
| Reply #3 on Sun 01 Jul 2018 11:24 AM (UTC) |
| Message
| Thanks, I do not know the first think about SQLite3 or databasing, any suggestions on where to start? Also simple plugin examples I find I learn the best from.
Thanks. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Mon 02 Jul 2018 06:26 AM (UTC) Amended on Mon 02 Jul 2018 06:27 AM (UTC) by Nick Gammon
|
| Message
| I have some posts about databases at:
http://www.gammon.com.au/db
http://www.gammon.com.au/sql
There are some examples there. It may be hard, however, if you aren't used to the general ideas behind SQL.
Try reading some SQL tutorials. Basically you:
- Create a table: CREATE TABLE ...
- Put items (rows) into the table: INSERT INTO ...
- Change things as required: UPDATE ...
- Get data back: SELECT ... FROM ...
Tables are generally a collection of like things (eg. inventory items). If a thing can have multiple "sub-things" (for example, a room with multiple exits) you generally (almost always) would have a second table. One for the room, and one for the exits. The exits table entries would "point" to the room they "belong" to.
If the room could contain other things (eg. shopkeepers) then you might make a third table, one which has the shopkeeper information. And if each shopkeeper stocked multiple items you might have another table with those items in it.
And now imagine that the same item (eg. a loaf of bread) could be sold by multiple shopkeepers. Then you might need another table again which connects the shopkeepers that sell bread to the bread item. You don't need this for a room exit, because an exit always belongs to a particular room, but bread might "belong" to multiple shopkeepers.
A good tutorial in SQL should walk you through this stuff.
Alternatively, stick to serializing tables, unless you have thousands of items. Be aware that if the program happens to crash while you are writing out the serialized file you might lose everything because you are overwriting the earlier file (unless you take steps to avoid that, like making a new file and renaming it when you are done).
SQLite3 is supposed to be pretty safe during a crash, as it has mechanisms to roll back the data to the last completed transaction. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
19,382 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top