Re: Reducing unncessary string copying



* Joakim Sindholt <opensource zhasha com> schrieb:

Hi,

> I entertained these 2 approaches a bit and the general slowdown (on my
> machine, an i686) resulted in approximately 10-15% overhead in the
> following test duplicating strings:

hui!

But, I guess, your system is not under memory presure. (as mine ;-o)

<snip>

> char *_strdup(const char *str)
> {
>     int len = strlen(str);
>     char *r = malloc(len+1);
>     memcpy(r, str, len+1);
>     return r;
> }

Not inlined or macro, so it will always do an full call.
Perhaps you could try it again w/ inline.

> cstr cstrdup(const cstr str)
> {
>     int len = strlen(str);
>     cstr r = (cstr)malloc(len+1+sizeof(cstrinfo))+sizeof(cstrinfo);
>     memcpy(r, str, len+1);
>     CSTR_INFO(r).flags = 0;
>     return r;
> }

Maybe optimizable for certain archs.

> I have however arrived at the conclusion that you should just leave C
> strings alone and if it bothers you that much, use a different language
> in the future. Frankly, regardless of approach, it will create an
> ABI/API nightmare in existing libraries and applications using g_*
> functions with strings.

hmm. my intention was to reduce the heap size. optimizing the
strings was my first idea.

perhaps we should also care of things like int sizes on 64bit, etc.


cu
-- 
----------------------------------------------------------------------
 Enrico Weigelt, metux IT service -- http://www.metux.de/

 phone:  +49 36207 519931  email: weigelt metux de
 mobile: +49 151 27565287  icq:   210169427         skype: nekrad666
----------------------------------------------------------------------
 Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme
----------------------------------------------------------------------


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