I would like to know what is the maximum length of a String when saving in the classic preferences System:
va开发者_如何学Cr prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref("com.exemple.namespace.preference", potentiallyLongString);
Couldn't find it in official documentation.
Note: I tried to type in more than 255, it works on Firefox 3.6, but I'm looking for a documented answer which would certify that length L
works since version V
.
Since there was no documentation, I just though of trying it anyway (at the most it'd have crashed my browser). I tried to the extent of 1,51,276 characters - and it worked perfectly fine. Trust me, I even matched the characters to test the reliability. :) Of course, doesn't mean you should use it regularly to those extents. ;). Just to give you an idea, that'd be around 30,000 words of English language, and has more number of characters than the whole script of the Movie Matrix (part 1).
I didn't try for more, as Notepad++ had started becoming slow in copying and pasting those many characters.
(Test Environment: Firefox 24, Windows 7 64 bit)
Edit: While I was trying this, I also noticed that even though it works for enormously large values, after some 4000 characters, Firefox starts giving a performance warning in the Error Console. So take what you want to from this.
There's no documentation on that. You shouldn't store unreasonably large strings in prefs -- if you're not sure if it will be reasonable, it's likely not a pref.
精彩评论