what the advantages of QSTR

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
fkeujjpdc
Posts: 13
Joined: Thu Mar 23, 2017 3:17 am
Location: china

what the advantages of QSTR

Post by fkeujjpdc » Tue Mar 28, 2017 7:35 am

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.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: what the advantages of QSTR

Post by deshipu » Tue Mar 28, 2017 8:44 am

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.

User avatar
fkeujjpdc
Posts: 13
Joined: Thu Mar 23, 2017 3:17 am
Location: china

Re: what the advantages of QSTR

Post by fkeujjpdc » Tue Mar 28, 2017 2:45 pm

your reply is very detail and wonderful,i got mush knowledge about QSTR from you ,thanks.

Post Reply