changeset 5993:5feb28cb62c8

*** empty log message ***
author Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
date Fri, 18 Feb 1994 13:24:41 +0000
parents c072fed85d62
children b50531f2f37e
files lwlib/lwlib-Xlw.c lwlib/lwlib.c
diffstat 2 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lwlib/lwlib-Xlw.c	Fri Feb 18 11:03:38 1994 +0000
+++ b/lwlib/lwlib-Xlw.c	Fri Feb 18 13:24:41 1994 +0000
@@ -71,13 +71,14 @@
 }
 
 /* creation functions */
+
 static Widget
 xlw_create_menubar (instance)
      widget_instance* instance;
 {
   Widget widget;
 
-  widget_value *tem = (widget_value *) XtMalloc (sizeof (widget_value));
+  widget_value *tem = malloc_widget_value (); 
 
   /* _XtCreate is freeing the object we passed,
      so make a copy that we free later.  */
@@ -89,7 +90,7 @@
 		      XtNmenu, tem,
 		      0);
 
-  XtFree (tem);
+  free_widget_value (tem);
 
   XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
   XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
@@ -106,7 +107,7 @@
   
   Widget widget;
 
-  widget_value *tem = (widget_value *) XtMalloc (sizeof (widget_value));
+  widget_value *tem = malloc_widget_value ();
 
   /* _XtCreate is freeing the object we passed,
      so make a copy that we free later.  */
@@ -119,7 +120,7 @@
 			     XtNhorizontal, False,
 			     0);
 
-  XtFree (tem);
+  free_widget_value (tem);
 
   XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
 
--- a/lwlib/lwlib.c	Fri Feb 18 11:03:38 1994 +0000
+++ b/lwlib/lwlib.c	Fri Feb 18 13:24:41 1994 +0000
@@ -112,6 +112,8 @@
 }
 
 static widget_value *widget_value_free_list = 0;
+static int malloc_cpt = 0;
+static int malloc_cpt_id = 0;
 
 widget_value *
 malloc_widget_value ()
@@ -126,6 +128,7 @@
   else
     {
       wv = (widget_value *) malloc (sizeof (widget_value));
+      malloc_cpt++;
     }
   memset (wv, 0, sizeof (widget_value));
   return wv;
@@ -140,8 +143,24 @@
 {
   if (wv->free_list)
     abort ();
-  wv->free_list = widget_value_free_list;
-  widget_value_free_list = wv;
+
+  if (malloc_cpt > 20)
+    {
+      /* When the number of already allocated cells is too big,
+	 We free it.  */
+      malloc_cpt_id++;
+      free (wv);
+      if (malloc_cpt_id > 20)
+	{
+	  malloc_cpt_id = 0;
+	  malloc_cpt = 0;
+	}
+    }
+  else
+    {
+      wv->free_list = widget_value_free_list;
+      widget_value_free_list = wv;
+    }
 }
 
 static void