javascript - Does a JSON file on disk, occupy the same amount of space when loaded into a var in memory? -
i store json files on disk (each small 4kb), , load them var when required. may have thousands of such files, , if space occupy in memory same occupy on disk, rather load them memory @ application start.
how can calculate how memory (ram) file occupies when create object ?
edit: know how save json files disk. not question. trying understand how memory (ram), json file occupy when load var. if know size of json file on disk, how can calculate how memory (ram) occupy when create javascript object file in node.js or in web browser ?
the files saved "plain text files". eg:
{"foo": { "bar": 1, "foo": { "bar": [ "foo", "bar" ], "foo":[ "bar", "foo" ] } } }
the amount of ram occupied object not same size of file. size of file number of bytes in it, amount of ram occupied object depends on values stored in it. example, in object this:
{ "bar": 1 }
when saved file, 1
single byte. however, if load object var
, 1
occupy 8 bytes, since number
.
take @ answer size of each datatype: https://stackoverflow.com/a/11900218/1611665
also, should take size of keys account (but that's pretty simple, it's twice as length
property if keys strings).
Comments
Post a Comment