inherit
249312
0
Nov 2, 2018 14:34:00 GMT -8
bartlesby
110
September 2017
bartlesby
|
Post by bartlesby on Aug 5, 2018 6:06:57 GMT -8
With something like a User Key, that has 4,000 bytes of storage, is the amount of space you have to work with calculated in terms of what data you put into it or does it include the formatting?
For instance, if I push two values (let's say the characters 'A' and 'B'), have I used two bytes of the key or have I used 6 bytes plus another two for the separation of the values and another two for the brackets that encapsulate them? I.E.:
A B = two bytes (ignore the space; only there to demonstrate two values). ["A", "B"] = ten bytes (space, comma, brackets, and quotes included).
Thanks in advance for any clarification.
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,779
January 2015
msg
|
Post by Lynx on Aug 5, 2018 9:29:29 GMT -8
Tagging Todge - as I'm not well-versed with keys yet.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,285
January 2004
todge
|
Post by Todge on Aug 5, 2018 14:00:55 GMT -8
If you save a string to a key, ordinarily the length of the string will be the memory used.. BUT.. Information sent to a server can only be text, so in our case, the array would be converted to a string first.. The space taken would be 9 bytes (2 brackets, 2 single byte values, 4 quotes and the comma), as you said.
If I'm worried about the amount of space taken when using JS Objects with keys, I usually convert them myself first, using the JSON.stringify() function, that way I can check the length first.
|
|
inherit
249312
0
Nov 2, 2018 14:34:00 GMT -8
bartlesby
110
September 2017
bartlesby
|
Post by bartlesby on Aug 5, 2018 15:56:08 GMT -8
If you save a string to a key, ordinarily the length of the string will be the memory used.. BUT.. Information sent to a server can only be text, so in our case, the array would be converted to a string first.. The space taken would be 9 bytes (2 brackets, 2 single byte values, 4 quotes and the comma), as you said. If I'm worried about the amount of space taken when using JS Objects with keys, I usually convert them myself first, using the JSON.stringify() function, that way I can check the length first. So if key space is a concern, would it then be more economical to store everything in a single string and parse it within a script? For instance, if I need to store 10 individual bytes in the key, if I push each one individually it would be 3 bytes each with the quotation marks, plus 9 commas and 2 brackets which is 41 bytes. If I store them as one string, it would be 10 bytes plus 2 quotation marks and 2 brackets which is 14 bytes.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,285
January 2004
todge
|
Post by Todge on Aug 5, 2018 16:08:28 GMT -8
If you save a string to a key, ordinarily the length of the string will be the memory used.. BUT.. Information sent to a server can only be text, so in our case, the array would be converted to a string first.. The space taken would be 9 bytes (2 brackets, 2 single byte values, 4 quotes and the comma), as you said. If I'm worried about the amount of space taken when using JS Objects with keys, I usually convert them myself first, using the JSON.stringify() function, that way I can check the length first. So if key space is a concern, would it then be more economical to store everything in a single string and parse it within a script? For instance, if I need to store 10 individual bytes in the key, if I push each one individually it would be 3 bytes each with the quotation marks, plus 9 commas and 2 brackets which is 41 bytes. If I store them as one string, it would be 10 bytes plus 2 quotation marks and 2 brackets which is 14 bytes. Definitely. In that case the most economical way would be to create one long string of characters, which can simply be split after the key is read.
|
|
inherit
249312
0
Nov 2, 2018 14:34:00 GMT -8
bartlesby
110
September 2017
bartlesby
|
Post by bartlesby on Aug 5, 2018 16:09:26 GMT -8
So if key space is a concern, would it then be more economical to store everything in a single string and parse it within a script? For instance, if I need to store 10 individual bytes in the key, if I push each one individually it would be 3 bytes each with the quotation marks, plus 9 commas and 2 brackets which is 41 bytes. If I store them as one string, it would be 10 bytes plus 2 quotation marks and 2 brackets which is 14 bytes. Definitely. In that case the most economical way would be to create one long string of characters, which can simply be split after the key is read. Excellent. Thank you for the help.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,285
January 2004
todge
|
Post by Todge on Aug 5, 2018 16:12:56 GMT -8
Not a problem.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Aug 8, 2018 4:23:06 GMT -8
Just a little bit of info regard "bytes" being mentioned here. Probably not important for most people, but wanted to share some info that I wrote a while back in my book.
|
|