Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 65368 invoked by uid 500); 11 Aug 2001 18:11:52 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 65356 invoked from network); 11 Aug 2001 18:11:52 -0000 Date: Sun, 12 Aug 2001 02:09:51 -0400 (EDT) From: Sterling Hughes X-X-Sender: To: Aaron Bannert Cc: Subject: Re: use of malloc in dso.c instead of apr_palloc? In-Reply-To: <20010811001633.A22820@clove.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N On Sat, 11 Aug 2001, Aaron Bannert wrote: > On Sat, Aug 11, 2001 at 12:25:11PM -0400, Sterling Hughes wrote: > > > > Well, as the overly long title suggests, is there any reason that > > malloc() is used in dso.c (unix and aix)? apr_palloc() seems > > fine for these purposes (temporary string). Also, as a side > > note, sizeof(char) is used in the allocation, which is extreaneous, > > because a char is always equivalent to one base unit of memory > > (well, at least that's how I interpret ANSII). > > If I remember my compiler class correctly, sizeof() gives a constant scalar > at compile-time. Any decent compiler will perform constant folding on > expressions like (sizeof(char)*12) before producing object code. This means > you should feel free to use sizeof() liberally if it helps readability. > I know gcc should optimize this out (so should most other compilers), just like a = 12 * 12 is translated to a = 144. Its more of a stylistic note, as: malloc(sizeof(char)*(strlen(str)+2)); doesn't look as nice as: malloc(strlen(str) + 2); since the sizeof(char) will never provide any functional benefits (no it won't hurt anything, but...) But all this was really an aside from the main point, should malloc() be used? :) -Sterling