ILockBytesOnHGlobal WriteAt性能随着时间的推移而降低(ILockBytesOnHGlobal WriteAt performance decreases over time)

编程入门 行业动态 更新时间:2024-10-27 06:20:36
ILockBytesOnHGlobal WriteAt性能随着时间的推移而降低(ILockBytesOnHGlobal WriteAt performance decreases over time)

我创建了ILockBytesOnHGlobal,我重复写入64k的数据。 我注意到,WriteAt性能随着时间的推移而下降。

性能下降的原因是什么? 这与流式增长有关吗? 这是我在做什么(用C#)

public override void Write(byte[] buffer, int offset, int count) { EnsureBufferSize(count); Marshal.Copy(buffer, offset, hGlobalBuffer, count); lockBytes.WriteAt(writeOffset, hGlobalBuffer, count, out temp); writeOffset += temp.ToUInt32(); }

I've created ILockBytesOnHGlobal and I write 64k of data repeatedly. What I've noticed is that WriteAt performance decreases over the time.

What could be the reason for the performance slow down? Does it have to do with stream growth? Here is what I'm doing (in C#)

public override void Write(byte[] buffer, int offset, int count) { EnsureBufferSize(count); Marshal.Copy(buffer, offset, hGlobalBuffer, count); lockBytes.WriteAt(writeOffset, hGlobalBuffer, count, out temp); writeOffset += temp.ToUInt32(); }

最满意答案

CreateILockBytesOnHGlobal文档说它使用GlobalReAlloc来增加内存块。 GlobalReAlloc将旧内存块中的数据复制到新的(和更大的)内存块,因此这会导致性能随着时间的推移而下降。

CreateILockBytesOnHGlobal documentation says that it uses GlobalReAlloc to increase the memory block. GlobalReAlloc copies the data from the old memory block to the new (and larger) memory block, so this causes performance to go down over time.

更多推荐

本文发布于:2023-08-07 23:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:性能   时间   WriteAt   ILockBytesOnHGlobal   decreases

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!