Improved memory allocation time
authorLeszek 'skolima' Ciesielski <skolima@gmail.com>
Fri, 19 Jan 2007 11:13:59 +0000 (11:13 -0000)
committerLeszek 'skolima' Ciesielski <skolima@gmail.com>
Fri, 19 Jan 2007 11:13:59 +0000 (11:13 -0000)
svn path=/trunk/mcs/; revision=71321

mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/Changelog
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciCalls.cs

index 95759caf9545e1f4bcbff0a1d582db236d9bbb3c..e8b4497724bf964a96733e26b6141078efde9ab5 100644 (file)
@@ -1,3 +1,6 @@
+2007-01-19 Leszek Ciesielski <skolima@gmail.com>
+       * OciCalls.cs: Speed up of the memory allocation
+
 2007-01-04 Leszek Ciesielski <skolima@gmail.com>
         * OciCalls.cs:
        * OciErrorHandle.cs:
index 4974c998a2964c873c447096ab450ec8b8f4f798..3c71112b9ea4fc0a75c7c30f1df4c409b7852273 100644 (file)
@@ -1148,14 +1148,30 @@ namespace System.Data.OracleClient.Oci
 
                #endregion
 
+               #region AllocateClear
+
+               private static bool IsUnix =
+               (int) Environment.OSVersion.Platform == 4 || (int) Environment.OSVersion.Platform == 128;
+
+               [DllImport("libc")]
+               private static extern IntPtr calloc (int nmemb, int size);
+
+               private const int GMEM_ZEROINIT = 0x40;
+
+               [DllImport("kernel32")]
+               private static extern IntPtr GlobalAlloc (int flags, int bytes);
+
                //http://download-uk.oracle.com/docs/cd/B14117_01/appdev.101/b10779/oci05bnd.htm#423147
                internal static IntPtr AllocateClear (int cb)
                {
-                       IntPtr result = Marshal.AllocHGlobal ( cb);
-                       for (int cleaner = 0; cleaner < cb; cleaner ++)
-                               Marshal.WriteByte (result, cleaner, 0);
-                       return result;
+                       if (IsUnix) {
+                               return calloc (1, cb);
+                       } else {
+                               return GlobalAlloc (GMEM_ZEROINIT, cb);
+                       }
+               }
+
+               #endregion AllocateClear
        }
 }
-}