| From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> | 
|---|---|
| To: | Mario Gonzalez <gonzalemario(at)gmail(dot)com> | 
| Cc: | Jaime Casanova <systemguards(at)gmail(dot)com>, editores(at)editores(dot)com(dot)co, postgresql <pgsql-es-ayuda(at)postgresql(dot)org> | 
| Subject: | Re: [GENERAL] Concurrencia | 
| Date: | 2006-03-16 16:54:39 | 
| Message-ID: | 20060316165439.GJ15329@surnet.cl | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-es-ayuda pgsql-general | 
Mario Gonzalez escribió:
>   Mhh, si te refieres a algun error de programacion en el manejo de
> memoria (memory leak) bueno, puede suceder. Como un ejemplo muy simple
> y adrede mira el caso de esta funcion
> 
> void
> example()
> {
>     char *b;
>     b = (char *)malloc(sizeof(char *));
> }
Observa que Postgres rara vez hace esto.  Generalmente se usa palloc()
en lugar de malloc().  La diferencia es que palloc() registra cada
bloque emplazado ("allocated") como perteneciente a un "contexto".  Con
cierta periodicidad el contexto puede "resetearse", en cuyo caso todos
los bloques emplazados se liberan automaticamente.  Por ejemplo tu
funcion podria hacer algo asi:
void example() {
	MemoryContext	context,
			oldcontext;
	int		i;
	context = AllocSetContextCreate( ... algunos parametros ...);
	oldcontext = MemoryContextSwitchTo(context);
	for (i = 0; i < 1000; i++) {
		char	*b;
		b = palloc(sizeof(char *));
	}
	MemoryContextSwitchTo(oldcontext);
	AllocSetDelete(context);
}	
por mucho que tu llames a esta funcion un millon de veces, nunca va a
usar mas de de (1000 * sizeof(char*)), aunque nunca hagas pfree().
Pero no entiendo que tiene que ver esto con la pregunta original :-)
-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mario Gonzalez | 2006-03-16 17:19:22 | Re: [GENERAL] Concurrencia | 
| Previous Message | Leonel Nunez | 2006-03-16 15:00:50 | Re: Replicacion de Datos | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Scott Ribe | 2006-03-16 16:57:46 | Re: Wisconsin Circuit Court Access (WCCA) on | 
| Previous Message | Scott Ribe | 2006-03-16 16:43:34 | Error I don't understand, losing synch with server |