I remembered that there is a mentioning about bstring can alloc string on the stack if they are small from some reading on the web when googling about the package. Is this true? After I read the readme.txt, it seems malloc is needed for bstring. So I am wondering if I get the wrong information from the web.
Best,
Zhichao
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The space for bstring's cannot be allocated from the stack if they are *writeable*. It is possible to wrap C strings that are declared on the stack into a bstring container, however that container will be a read-only bstring. Removing the capability of writing to string data that is in auto/stack memory is a requirement for the high level of safety achieved by Bstrlib. To ensure that Bstrlib's use of malloc() on every string does not become a performance problem, hoisting the string initialization to an outer loop and reusing the string is the typical recommended strategy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I remembered that there is a mentioning about bstring can alloc string on the stack if they are small from some reading on the web when googling about the package. Is this true? After I read the readme.txt, it seems malloc is needed for bstring. So I am wondering if I get the wrong information from the web.
Best,
Zhichao
The space for bstring's cannot be allocated from the stack if they are *writeable*. It is possible to wrap C strings that are declared on the stack into a bstring container, however that container will be a read-only bstring. Removing the capability of writing to string data that is in auto/stack memory is a requirement for the high level of safety achieved by Bstrlib. To ensure that Bstrlib's use of malloc() on every string does not become a performance problem, hoisting the string initialization to an outer loop and reusing the string is the typical recommended strategy.