Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 25-Feb-17 14:40pm

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900