FeatureClassのメモリ格納とプロセスのメモリ使用


メモリ格納はサーバ問い合わせやファイルI/Oよりは速度を稼げるが使いどころは限定される。
静的なデータでかつシンプルフィーチャ、アノテーションでないもの等。
今ひとつメモリ挙動が読めないが。

#if DEBUG
        StringBuilder sb = new StringBuilder();

        Process curtProcess = Process.GetCurrentProcess();

        double pgSize = curtProcess.PagedMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB
        double vmSize = curtProcess.PrivateMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB
        double physicaMemMB = curtProcess.WorkingSet64
            / 1024.0 //KB
            / 1024.0; //MB
        double virtualMemMB = curtProcess.VirtualMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB

        Debug.Print("処理前:Paged:{0} Private:{1} WorkingSet:{2} VMSize:{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);

        sb.Append("処理フェーズ,PagedMemorySize64,PrivateMemorySize64,物理メモリ,仮想メモリ");
        sb.Append(Environment.NewLine);
        sb.AppendFormat("処理前,{0},{1},{2},{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);
#endif //DEBUG

        using (ComReleaser com = new ComReleaser())
        {
            string connectionString = "SERVER=DUMMY;DATABASE=データベース;INSTANCE=sde:sqlserver:インスタンス;USER=ユーザ;PASSWORD=パスワード;VERSION=dbo.DEFAULT";
            string fcName = "フィーチャクラス名";

            Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
            IWorkspaceFactory2 wsf = (IWorkspaceFactory2)Activator.CreateInstance(t);
            com.ManageLifetime(wsf);

            IFeatureWorkspace fw = (IFeatureWorkspace)wsf.OpenFromString(connectionString, 0);
            com.ManageLifetime(fw);

            IFeatureClass fc = fw.OpenFeatureClass(fcName);
            com.ManageLifetime(fc);

            IRecordSetInit rInit = new RecordSetClass();
            com.ManageLifetime(rInit);

            ISpatialFilter spFileter = new SpatialFilterClass();
            com.ManageLifetime(spFileter);

            spFileter.GeometryField = fc.ShapeFieldName;
            IEnvelope env = new EnvelopeClass();
            com.ManageLifetime(env);
            env.PutCoords(120, 20, 150, 50);
            env.SpatialReference = ((IGeoDataset)fc).SpatialReference;
            spFileter.Geometry = env;
            spFileter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            rInit.SetSourceTable((ITable)fc, spFileter);
            IRecordSet2 rc2 = (IRecordSet2)rInit;

            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
            com.ManageLifetime(workspaceFactory);

            IWorkspaceName workspaceName = workspaceFactory.Create(null, "MyWorkspace", null, 0);
            com.ManageLifetime(workspaceName);
            IName name = (IName)workspaceName;

            IWorkspace workspace = (IWorkspace)name.Open();
            com.ManageLifetime(workspace);

            IFeatureClass memFc = (IFeatureClass)rc2.SaveAsTable(workspace, fcName);
            com.ManageLifetime(memFc);

#if DEBUG
            curtProcess = Process.GetCurrentProcess();

            pgSize = curtProcess.PagedMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB
            vmSize = curtProcess.PrivateMemorySize64
                / 1024.0 //KB
                / 1024.0; //MB
            physicaMemMB = curtProcess.WorkingSet64
                / 1024.0 //KB
                / 1024.0; //MB
            virtualMemMB = curtProcess.VirtualMemorySize64
                / 1024.0 //KB
                / 1024.0; //MB

            Debug.Print("処理後:Paged:{0} Private:{1} WorkingSet:{2} VMSize:{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);
            sb.Append(Environment.NewLine);
            sb.AppendFormat("処理後,{0},{1},{2},{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);

            //c1-30237?放
            ((IDataset)memFc).Delete();
            ((IDataset)workspace).Delete();

#endif //DEBUG

        }//end com

#if DEBUG
        curtProcess = Process.GetCurrentProcess();

        pgSize = curtProcess.PagedMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB
        vmSize = curtProcess.PrivateMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB
        physicaMemMB = curtProcess.WorkingSet64
            / 1024.0 //KB
            / 1024.0; //MB
        virtualMemMB = curtProcess.VirtualMemorySize64
            / 1024.0 //KB
            / 1024.0; //MB

        Debug.Print("解放後:Paged:{0} Private:{1} WorkingSet:{2} VMSize:{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);

        sb.Append(Environment.NewLine);
        sb.AppendFormat("解放後,{0},{1},{2},{3}", pgSize, vmSize, physicaMemMB, virtualMemMB);

        System.Windows.Forms.Form debugForm = new System.Windows.Forms.Form();
        System.Windows.Forms.TextBox txtbox = new System.Windows.Forms.TextBox();
        txtbox.Multiline = true;
        txtbox.Text = sb.ToString();
        txtbox.Dock = System.Windows.Forms.DockStyle.Fill;

        debugForm.Controls.Add(txtbox);
        debugForm.Show();

#endif //DEBUG

参照は下記

using System;
using System.Text;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DataSourcesGDB;
using System.Diagnostics;
カテゴリー: 開発 タグ: パーマリンク