Return-Path: owner-new-httpd Received: by taz.hyperreal.com (8.6.10/8.6.5) id OAA04356; Mon, 10 Apr 1995 14:41:55 -0700 Received: from neon.netscape.com by taz.hyperreal.com (8.6.10/8.6.5) with ESMTP id OAA04350; Mon, 10 Apr 1995 14:41:53 -0700 Received: (from robm@localhost) by neon.netscape.com (950215.SGI.8.6.10/8.6.9) id OAA20501; Mon, 10 Apr 1995 14:37:24 -0700 Date: Mon, 10 Apr 1995 14:37:24 -0700 From: Rob McCool Message-Id: <199504102137.OAA20501@neon.netscape.com> To: new-httpd@hyperreal.com Subject: why C's string management sucks In-Reply-To: References: <199504100234.TAA28192@neon.netscape.com> Sender: owner-new-httpd@hyperreal.com Precedence: bulk Reply-To: new-httpd@hyperreal.com /* * "Re: votes" by Brian Behlendorf * written Sun, 9 Apr 1995 19:09:22 -0800 (PST) * > Something like (in psuedo-code) > /* somewhere in a header file */ > char URL_string_stack[MAX_STRING_LENGTH]; > char *URL_string = URL_string_stack > int using_URL_string_heap; > /* in the body of the code */ > if (size_of_resource_required > MAX_STRING_LENGTH) { > URL_string = (char *)malloc(size_of_resource_required); > using_URL_string_heap = 1; > } > (do whatever you need to do) > if (using_URL_string_heap) { > free(URL_string); > using_URL_string_heap = 0; > } > URL_string = URL_string_stack; * Free()ing it should make sure it doesn't leak in rst's no-forking * model. */ You could do that, but if you're going to do that why not use malloc() to begin with? With the setup above, you have to keep track of three separate variables for every string. You'd be better off using malloc() and then realloc() later when you need more space. The advantage of using local vars on the stack is that in a simpler context, it's easier to manage. When the project started two years ago, that decision made sense. As things got more and more complex it made less and less sense. --Rob