如何使用marshal.structuretoptr使用结构化类型追加记录。 [英] How to use marshal.structuretoptr to append records using structured types.

查看:111
本文介绍了如何使用marshal.structuretoptr使用结构化类型追加记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Visual Basic的新手,并且在写入文件之前使用Marshal.StructureToPtr将结构存储到已分配的内存中。



我的问题是,如果我写更多使用此函数的一条记录(使用结构类型),第二条记录会替换分配的内存中的第一条记录吗?换句话说,每次使用该功能时数据都会附加或替换吗?



我尝试过的事情:



没试过,因为函数没有提供任何可能的指示。

I am new to Visual Basic and exploring using Marshal.StructureToPtr to store structures into allocated memory before writing to file.

My question is that if I write more than one record (using structure type) using this function, would the second record replace the first in the memory allocated? In other words, does data append or replace everytime I use the function?

What I have tried:

Have not tried as the function doesn't provide any indication that this is possible.

推荐答案

只要你继续提供一个正确指向您希望将结构复制到的位置,而非托管代码支持您将此数据附加到任何现有数据,当然,您可以使用它在您的内存块中追加数据。它不会为你做的。您必须执行指针数学运算才能将指针正确移动到下一个结构将被复制到的位置。



如果你不移动指针那么你'重新覆盖以前的东西。如果你不小心你会有泄漏,因为对旧对象的引用不会正确递减。
So long as you keep providing a correct pointer to where you want the structure copied to and you unmanaged code supports you appending this data to any existing data, sure, you can use it to "append" data in your block of memory. It's not going to do it for you. YOU must perform the pointer math to move the pointer appropriately top where the next structure is going to be copied to.

If you don't move the pointer then you're going to overwrite what was there before. If you're not careful you're going to have a leak as references to the old object are not going to be decremented properly.


这篇关于如何使用marshal.structuretoptr使用结构化类型追加记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆