httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ed <>
Subject Loading permanenly memory area.
Date Fri, 28 Sep 2007 20:33:16 GMT
> Hello,
> How to load memory permanently between request?
> Server handles  ap_hook_handler when request is made, but when request
> finish memory should be free ().
> Any method to load memory when module start with apache, and unload
> when apache shut down ?


I've just joined this list, and was looking through the archives to find
a FAQ or something.

Apologies if this is already answered.

I think what you're looking for is something that can allocate global
memory, which is generally a bad idea - unless you're going to instate
your own locking mechanism, to prevent requests clobbering each other
with the memory.

void *global_pointer = NULL;

int module_handler( ... ) {
	if( global_pointer == NULL ) {
		global_pointer = malloc( BUFFER*20 );

		 * uh oh, no free memory
		if( global_pointer == NULL ) {
			return( EXIT_FAILURE );

Now, obviously the problem here, is that every request will try and
access the same block of memory, generally a bad idea. You will have to
put your own method of synchronisation into the module.

Generally, getting a memory from the kernel is no problem, and happens
very quickly, so it's not a big concern to call malloc once or twice per

The Optical Cable to the FTP Server is smelling funky because of an
errant well-driller. The Cult of the Dead Cow is pumping a grumpy.
:: ::

View raw message