git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] Added generic string handling code.

From
TSTimo Sirainen <tss@iki.fi>
Date
May 20, 2007, 10:27 UTC
Message-ID
<B5F56D1C-4EC2-4A79-9489-B4F1C9FC9BA7@iki.fi>
In-Reply-To
<20070520100155.GB3106@steel.home>
On 20.5.2007, at 13.01, Alex Riesen wrote:
Show 6 quoted lines
> Timo Sirainen, Sun, May 20, 2007 04:24:29 +0200:
>> So here's my try on starting with something simple. Unlike almost all
>> other string handling libraries, it doesn't allocate the memory
>> dynamically.
>
> Sometimes you _need_ dinamic memory allocation.

It's easy to use the same str_*() functions to implement dynamic memory allocation. I think I could have done a bit different naming, like maybe:

extern struct string *str_alloc(unsigned int len); extern void str_append(struct string *str, const char *cstr);

#define static_string(name, size) .. #define sstr_append(str, cstr) str_append(&(str).string, cstr)

Show 7 quoted lines
>> This makes it really easy to convert existing code to use it. I'm
>> including some example changes in the other patches. Besides making
>> the code safer, it can also make it faster, especially those
>> strcat() replacements.
>
> It is also bigger, heavier on stack and sometimes slower because of
> more function calls involved.

I would hardly call 8 extra bytes on stack heavier. Also if this was used everywhere I wouldn't be surprised if it made the code faster, because it would remove a lot of overflow checking code so more code will fit into L1 cache.

Previous: Alex RiesenNext: Petr Baudis
Message 3 of 7 in “Added generic string handling code.”
  1. 1/3 Added generic string handling code.Timo Sirainen, May 20, 2007
  2. Alex RiesenMay 20, 2007
  3. Timo SirainenMay 20, 2007
  4. Petr BaudisMay 22, 2007
  5. Timo SirainenMay 23, 2007
  6. Petr BaudisMay 23, 2007
  7. Timo SirainenMay 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.