httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Behlendorf <br...@wired.com>
Subject Re: votes
Date Mon, 10 Apr 1995 03:09:22 GMT
On Sun, 9 Apr 1995, Rob McCool wrote:
> /*
>  * "Re: votes" by Brian Behlendorf <brian@wired.com>
>  *    written Sun, 9 Apr 1995 18:27:30 -0800 (PST)
>  * 
>  * Is there some reason that extra space just couldn't have been
>  * allocated when needed?  Or is there no efficient way to tell if
>  * more memory is going to be needed when string copying is done?
>  *
>  */
> 
> Had I used dynamic allocation from the heap instead of local variables
> on the stack, then more space could have been allocated. But there
> isn't any way to change the amount of space allocated by a local
> variable at runtime that I know of.

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.

	Brian "Sticking to Perl for now, or maybe I'll go hack Linux for a living" B.

--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
brian@hotwired.com  brian@hyperreal.com  http://www.hotwired.com/Staff/brian/


Mime
View raw message