Menu

Can bstring alloc a string on the stack

2008-06-10
2013-04-29
  • Zhichao Hong

    Zhichao Hong - 2008-06-10

    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

     
    • Paul Hsieh

      Paul Hsieh - 2008-06-16

      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.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.