Page 1 of 1

what the advantages of QSTR

Posted: Tue Mar 28, 2017 7:35 am
by fkeujjpdc
what the advantages of QSTR,it's only to avoid duplication of strings and reduce rom size?
Micropython uses a hash table index string but does not faster than original string.

Re: what the advantages of QSTR

Posted: Tue Mar 28, 2017 8:44 am
by deshipu
QSTR is a mechanism for string interning. It basically lets you replace a string with a number. This has numerous advantages: first, as you noted, it saves some flash size, since the string doesn't have to be stored multiple times; second, it also saves memory, since the string itself is stored in flash, and in memory you can simply just store the number; third, it speeds up comparisons, especially for strings that have a common prefix -- with normal strings, you need to compare them byte by byte, until you hit a character that is different; comparing numbers is much easier and pretty much instant.

Re: what the advantages of QSTR

Posted: Tue Mar 28, 2017 2:45 pm
by fkeujjpdc
your reply is very detail and wonderful,i got mush knowledge about QSTR from you ,thanks.