在C#中释放非托管代码(Freeing up of unmanaged code in C#)
我从C#应用程序中调用一段非托管C ++代码来计算离散时间信号的快速傅立叶变换。
我拨打这样的电话
IntPtr ptr = ComputeFFTW(packetSig, packetSig.Length, (int)samplFrequency,(int)fftPoints); unsafe { double *dPtr = (double*)ptr; for(int l = 0; l < fftData.Length; l++) { fftData[l] = dPtr[l]; } }
虽然这段代码工作正常并且给了我想要的结果,但我可以看到在计算过程中会出现性能损失(内存泄漏)。 CLR无法回收本地(双)变量,我的应用程序大大增加了RAM空间。
你们中的任何人都可以建议我可能做错的地方。
从我这边,我使用ANTS Mem Profiler运行我的应用程序,我可以在快照上看到双重对象几乎声称> 150MB的mem空间。 这是正常的行为吗?
Class Name Live Size (bytes) Live Instances Double[] 150,994,980 3
任何帮助在这方面赞赏Srivatsa
I call a piece of an unmanaged C++ code from my C# application to calculate fast fourier transform of a discrete time signal.
I make a call something like this
IntPtr ptr = ComputeFFTW(packetSig, packetSig.Length, (int)samplFrequency,(int)fftPoints); unsafe { double *dPtr = (double*)ptr; for(int l = 0; l < fftData.Length; l++) { fftData[l] = dPtr[l]; } }
Though this snippet of code works fine and gives me the desired results, i can see that there is sort of performance hit (memory leak) is incurred while calculation is in progress. The CLR fails to reclaim the local (double) variables and my application gobbles up RAM space considerably.
Can anyone of you suggest the places where i might be doing it wrong.
From my side, I ran my application using ANTS Mem Profiler and i can see on the snapshot that the double objects nearly claim >150MB of the mem space. Is this a normal behaviour ??
Class Name Live Size (bytes) Live Instances Double[] 150,994,980 3
Any help is appreciated in this regard Srivatsa
原文:https://stackoverflow.com/questions/3802251
相关问答
更多-
获取最新的sqlite3最简单的方法不是重建python ,而是安装pysqlite包,它是标准库的sqlite3模块的最新版本。 它包括对更新的sqlite3功能的支持,并且向上兼容。 更多细节在这里 。 Rather than rebuilding python, the simplest way to get the most recent sqlite3 is to install the pysqlite package which is the more up-to-date version o ...
-
文件说: 如果右侧是绑定到字符串的参数 ,则只有在使用sqlite3_prepare_v2()或sqlite3_prepare16_v2()编译包含表达式的预 准备语句时才会尝试此优化。 如果右侧是参数并且使用sqlite3_prepare()或sqlite3_prepare16()准备语句,则不会尝试LIKE优化。 旧版本的pysqlite模块使用sqlite3_prepare() 。 The documentation says: If the right-hand side is a paramete ...
-
您可以使用消费者生产者模式。 例如,您可以创建在线程之间共享的队列。 从Web获取数据的第一个线程将共享队列中的这些数据排入队列。 拥有数据库连接的另一个线程从队列中取出数据并将其传递给数据库。 You can use consumer-producer pattern. For example you can create queue that is shared between threads. First thread that fetches data from the web enqueues t ...
-
仅当两个事务实际冲突时, 超时才有意义。 The timeout matters only if two transactions actually conflict.
-
此行为取决于版本。 如果您想要保证重新排序,则必须自己将所有记录复制到新表中。 (这适用于隐式和显式ROWID。) This behaviour is version dependent. If you want a guaranteed reordering, you have to copy all records into a new table yourself. (This works with both implicit and explicit ROWIDs.)
-
我应该为每个Sqlite3事务调用connect()和close()吗?(Should I call connect() and close() for every Sqlite3 transaction?)[2021-11-04]
您可以重复使用相同的连接。 你也可以使用连接(和光标)作为上下文管理器,这样你就不需要明确地调用close 。 def insert(conn, args): with conn.cursor() as c: c.execute(...) conn.commit() with connect('db.py') as conn: insert(conn, ...) insert(conn, ...) insert(conn, ...) 没有理由关闭与 ... -
从你的评论中,你的问题是你预先安装的sqlite 3.7比你的第三方3.8更高。 这意味着当你建立pysqlite2 ,默认情况下,它会找到并使用3.7,所以它对你没有任何好处。 你可能不想改变你的整个路径来处理这个问题。 但是,没关系,只要在构建时首先发现3.8,那么在运行时首先出现什么并不重要; 到3.8的路径将被烘焙到模块中。 有很多方法可以做到这一点,但最简单的是这样的: $ brew install sqlite3 $ sudo -s # LDFLAGS=-L/usr/local/opt/sqli ...
-
看起来更简单的方法是将其改编成Enum本身: class SqliteEnum(enum.Enum): def __conform__(self, protocol): if protocol is sqlite3.PrepareProtocol: return self.name 然后使用SqliteEnum作为其他Enum类的基础。 Looks like the easier way is to build the adaptation into the ...
-
'从sqlite3导入dbapi2为sqlite3'vs'导入sqlite3'?('from sqlite3 import dbapi2 as sqlite3' vs 'import sqlite3'?)[2022-01-19]
他们是一样的。 在我的Python安装(v2.6)的Lib/目录中, sqlite3包中包含一个带有以下内容的__init__.py文件: from dbapi2 import * 这意味着两种导入方式是完全相同的。 也就是说,我绝对推荐使用import sqlite3因为这是文档化的方法。 They are the same. In the Lib/ directory of my Python installation (v2.6), the sqlite3 package contains a __ ... -
如果要使用Python的自动事务处理,请将isolation_level保留为其默认值,或将其设置为三个级别之一。 如果要进行自己的事务处理,则必须通过将isolation_level设置为None来阻止Python自行执行。 If you want to use Python's automatic transaction handling, leave isolation_level at its default value, or set it to one of the three levels. ...