[PATCH] Introduce picture-object pool to avoid malloc/free overhead.
Jonathan Morton
jmorton at sd070.hel.movial.fi
Mon Jun 8 02:18:02 PDT 2009
---
render/picture.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/render/picture.c b/render/picture.c
index 5f86c7c..c94add0 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -703,6 +703,11 @@ SetPictureToDefaults (PicturePtr pPicture)
pPicture->pSourcePict = 0;
}
+/* Avoid calling malloc every time one of these is needed */
+#define PICTURE_POOL_SIZE (4)
+static PicturePtr PicturePool[PICTURE_POOL_SIZE] = {NULL};
+static uint32_t PicturePoolTop = 0;
+
PicturePtr
CreatePicture (Picture pid,
DrawablePtr pDrawable,
@@ -715,7 +720,11 @@ CreatePicture (Picture pid,
PicturePtr pPicture;
PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen);
- pPicture = (PicturePtr)xalloc(sizeof(PictureRec));
+ if(PicturePoolTop)
+ pPicture = PicturePool[--PicturePoolTop];
+ else
+ pPicture = (PicturePtr)xalloc(sizeof(PictureRec));
+
if (!pPicture)
{
*error = BadAlloc;
@@ -1531,7 +1540,11 @@ FreePicture (pointer value,
}
}
dixFreePrivates(pPicture->devPrivates);
- xfree (pPicture);
+
+ if(PicturePoolTop < PICTURE_POOL_SIZE)
+ PicturePool[PicturePoolTop++] = pPicture;
+ else
+ xfree (pPicture);
}
return Success;
}
--
1.5.6.3
--=-sSulcgRJlPy19NpCTn/b--
More information about the xorg-devel
mailing list