You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by devel <de...@pas-world.com> on 2007/08/03 17:45:44 UTC

Loading permanenly memory area.

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 ?


-- 
--
Publicidad http://www.pas-world.com


Re: Loading permanenly memory area.

Posted by Nick Kew <ni...@webthing.com>.
On Fri, 03 Aug 2007 17:45:44 +0200
devel <de...@pas-world.com> wrote:

> 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 ?

http://www.apachetutor.org/dev/pools

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Loading permanenly memory area.

Posted by ed <ed...@s5h.net>.
> 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 ?

Hi,

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
request.

-- 
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.
:: http://www.s5h.net/ :: http://www.s5h.net/gpg