Optimize memory allocates in metarecords

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





ChangeLog:

     Avoid excessive heap memory reallocation when playing Windows
     metarecords in memory.

Description:

     Keep track of previously allocated memory size in the METAFILEDRV_PDEVICE
     structure to avoid useless and expensive heap reallocation each time
     a metarecord is written in memory.

Warren Baird : Warren_Baird@cimmetry.com
Xavier Servettaz

diff -ur clean/wine/dlls/gdi/mfdrv/metafiledrv.h
wine/dlls/gdi/mfdrv/metafiledrv.h
--- clean/wine/dlls/gdi/mfdrv/metafiledrv.h   Wed Jan 29 15:30:25 2003
+++ wine/dlls/gdi/mfdrv/metafiledrv.h    Fri Jan 31 16:29:32 2003
@@ -34,6 +34,7 @@
     METAHEADER  *mh;           /* Pointer to metafile header */
     UINT       nextHandle;     /* Next handle number */
     HANDLE     hFile;          /* Handle for disk based MetaFile */
+    size_t     allocatedSize;  /* size of allocated memory */
 } METAFILEDRV_PDEVICE;


diff -ur clean/wine/dlls/gdi/mfdrv/init.c  wine/dlls/gdi/mfdrv/init.c
--- clean/wine/dlls/gdi/mfdrv/init.c     Wed Jan 29 15:30:25 2003
+++ wine/dlls/gdi/mfdrv/init.c     Fri Jan 31 16:25:48 2003
@@ -184,6 +184,8 @@
     physDev->mh->mtMaxRecord    = 0;
     physDev->mh->mtNoParameters = 0;

+    physDev->allocatedSize = 2 * physDev->mh->mtSize;
+
     return dc;
 }

@@ -382,9 +384,22 @@
     {
     case METAFILE_MEMORY:
     len = physDev->mh->mtSize * 2 + rlen;
-    mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, len );
-        if (!mh) return FALSE;
-        physDev->mh = mh;
+    /* reallocate memory if needed */
+    if (len > physDev->allocatedSize){
+        if (!physDev->allocatedSize) {
+             ERR("Unable to write record to unallocated memory\n");
+              return FALSE;
+         }
+         /*expand size*/
+         physDev->allocatedSize = (size_t)(1.2* physDev->allocatedSize + rlen);
+         mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh,
physDev->allocatedSize);
+         if (!mh) {
+             ERR("Unable to Reallocate Heap memory\n");
+              return FALSE;
+         }
+         physDev->mh = mh;
+         TRACE("Reallocated metafile: new size is
%d\n",physDev->allocatedSize);
+    }
     memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
         break;
     case METAFILE_DISK:




[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux