From owner-freebsd-current Fri Aug 7 07:16:56 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA11043 for freebsd-current-outgoing; Fri, 7 Aug 1998 07:16:56 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from tim.xenologics.com (tim.xenologics.com [194.77.5.24]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA11033 for ; Fri, 7 Aug 1998 07:16:51 -0700 (PDT) (envelope-from seggers@semyam.dinoco.de) Received: (from uucp@localhost) by tim.xenologics.com (8.8.5/8.8.8) with UUCP id QAA01227; Fri, 7 Aug 1998 16:06:56 +0200 (MET DST) Received: from semyam.dinoco.de (semyam.dinoco.de [127.0.0.1]) by semyam.dinoco.de (8.8.8/8.8.8) with ESMTP id MAA03715; Fri, 7 Aug 1998 12:11:01 +0200 (CEST) (envelope-from seggers@semyam.dinoco.de) Message-Id: <199808071011.MAA03715@semyam.dinoco.de> To: Bruce Evans cc: syko@sykotik.org, dg@root.com, freebsd-current@FreeBSD.ORG, freebsd@xaa.iae.nl, narvi@haldjas.folklore.ee, seggers@semyam.dinoco.de Subject: Re: memory leaks in libc In-reply-to: Your message of "Fri, 07 Aug 1998 02:36:07 +1000." <199808061636.CAA00012@godzilla.zeta.org.au> Date: Fri, 07 Aug 1998 12:11:01 +0200 From: Stefan Eggers Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Bruce Evans wrote: > The env functions are already costly. They use dumb linear searches > and malloc(), and don't alloc a little more than necessary so that the > environment can grow a little without reallocation. Garbage collection Maybe the ideal solution would be to put the variables one encounters on a linear search into a more convenient data structure like a tree for later references and on subsequent getenv's one first checks in the tree for the variable and if it is not there starts from the point where the last linear search ended. If we brought over all variables we only consult the tree. Settings by setenv get put into the tree right away. To get the memory leak fixed each node entry contains a boolean which indicates the origin of the string, i.e. false for those we got from the list and true for those we malloced. For convenient subprocess creation where one needs an array of poin- ters to the environment variable settings one could have a parallel array of pointers and put an index into this array in the nodes. Then one can easily update this array while one manipulates the node. Does that sound reasonable? It would make frequent requests for the same variable fast and fixes the memory leak. The disadvantage is the time penalty for a variable lookup where the variable is not already in the tree and that we need a little bit more memory for the nodes. Stefan. -- Stefan Eggers Lu4 yao2 zhi1 ma3 li4, Max-Slevogt-Str. 1 ri4 jiu3 jian4 ren2 xin1. 51109 Koeln Federal Republic of Germany To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message