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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 20.5.2007, at 13.01, Alex Riesen wrote:

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)


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.



Attachment: PGP.sig
Description: This is a digitally signed message part


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux