On Mon, May 21, 2012 at 3:07 PM, Glenn Fowler <[email protected]> wrote:
>
> On Sun, 20 May 2012 21:13:58 +0200 Irek Szczesniak wrote:
>> Does someone know why _ast_strdup calls calloc instead of malloc? I
>
> it was written before we added the oldof() companion to newof()
> strdup() just changed to use oldof()
I did a small experiment on Solaris to see how much ksh uses
|memset()| to zero-fill a memory area. The following line captures all
calls to |memset()| in a debug build (optimised builds may inline
|memset()| for small fixed sizes, ruining the experiment) and
explicitly prints lines for sizes below 16 bytes:
-- snip --
$ (truss -u :: ./arch/sol11.i386/bin/ksh -c 'print hello' ) 2>&1 |
egrep -- '-> libc:memset' | ./arch/sol11.i386/bin/ksh -c
'integer totalsize=0 ; while read l ; do
dummy=${l/~(E-g)\((.+),(.+),(.+)(,(.+))?\)} ; integer
size=${.sh.match[3]}; (( totalsize+=size )) ; (( size < 16 )) &&
printf "size=%d ; %q\n" size "$l" ; done ; printf "#totalsize=%d\n"
totalsize'
-- snip --
For ast-ksh.2012-05-18 I get around 30k filled with '\0' by |memset()|
while around 6k are sizes below 16 bytes.
One interesting sequence is the following usage which is used _VERY_ often:
-- snip --
/1@1: -> ksh:dttree(0xfed94180, 0xfed93fa4, 0x1)
/1@1: -> ksh:_dttype2005(0xfed94180, 0x1)
/1@1: <- ksh:_dttype2005() = 1
/1@1: -> libc:memset(0x8047558, 0x0, 0x8)
/1@1: <- libc:memset() = 0x8047558
/1@1: -> ksh:nv_compare(0xfed94180, 0x8221100, 0x82210f4, 0x823ea88)
/1@1: -> libc:strcmp(0x8221100, 0x82210f4)
/1@1: <- libc:strcmp() = 9
/1@1: <- ksh:nv_compare() = 9
/1@1: -> ksh:_dtmake(0xfed94180, 0xfed93fa4, 0x1)
/1@1: <- ksh:_dtmake() = 0xfed93fa4
/1@1: <- ksh:dttree() = 0xfed93fa4
-- snip --
I don't know exactly but using |memset()| for very small sizes may be
inefficient because of the huge overhead of the function call.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers