[PATCH] mieqProcessInputEvents - Lessen memory overhead

Jeremy Huddleston jeremyhu at freedesktop.org
Sat Dec 13 00:58:00 PST 2008


This patch updates mieqProcessInputEvents to not xcalloc() for every  
event it sees.

diff --git a/mi/mieq.c b/mi/mieq.c
index cb940e4..b865d82 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -313,7 +313,8 @@ mieqProcessInputEvents(void)
      int x = 0, y = 0;
      int type, nevents, evlen, i;
      ScreenPtr screen;
-    xEvent *event;
+    static xEvent *event = NULL;
+    static size_t event_size = 0;
      DeviceIntPtr dev = NULL,
                   master = NULL;

@@ -323,7 +324,10 @@ mieqProcessInputEvents(void)
          /* GenericEvents always have nevents == 1 */
          nevents = e->nevents;
          evlen   = (nevents > 1) ? sizeof(xEvent) : e->events->evlen;
-        event   = xcalloc(nevents, evlen);
+        if((nevents * evlen) > event_size) {
+            event_size = nevents * evlen;
+            event = (xEvent *)xrealloc(event, event_size);
+        }

          if (!event)
              FatalError("[mi] No memory left for event processing.\n");
@@ -381,8 +385,6 @@ mieqProcessInputEvents(void)
                      master->public.processInputProc(masterEvents- 
 >event, master,
                                                      nevents);
              }
-
-            xfree(event);
          }

          /* Update the sprite now. Next event may be from different  
device. */




More information about the xorg mailing list