Converting unmanaged struct -> CLI value struct

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm having an issue converting an unmanaged struct to a CLI managed
struct. It's a value struct and this cannot be changed.

[StructLayout(LayoutKind::Sequential, CharSet=CharSet::Ansi, Pack=1)]
public value struct UpdateItem
{
public:

[MarshalAs(UnmanagedType::ByValTStr, SizeConst=50)]
System::String ^Name;

[MarshalAs(UnmanagedType::ByValTStr, SizeConst=50)]
System::String ^Address;

[MarshalAs(UnmanagedType::ByValTStr, SizeConst=10)]
System::String ^Envelope;

[MarshalAs(UnmanagedType::ByValTStr, SizeConst=30)]
System::String ^Record;

virtual System::String^ ToString() override;
void SetDefaultValues();
};

But I cannot use

Marshal::PtrToStructure((IntPtr)&item, UpdateItem_); Because it has
issues apparently with the fact the managed struct is a value type. I
could copy these items manually, but this conversion is going to
happen, quite possible, in excess of 11 times a second, and gcnew'ing
these four managed strings each time is unacceptable. And I know
they're managed, and they will get Garbage Collected; but anyone when
this runs, I promise you the GC isn't running enough for me. The
memory continues to creep up, and up. Any solutions?

THank you in advance.

.



Relevant Pages

  • Re: ctime double double check
    ... with converting the time. ... However I couldn't find anything in the standard that specifies ... how the struct tm - time_t conversions should be done which means ... storing date as a string of characters and it may look like in ...
    (comp.lang.c)
  • Re: [PATCH] Fix proc_file_write missing ppos update
    ... You'd better start converting to struct file_operations::write now. ... someone who understands the specific driver code better should ... struct proc_dir_entry *parent, ...
    (Linux-Kernel)
  • Re: Rallocating a struct * *
    ... > Following shows allocation of my struct: ... After converting your code to C, I was able to realloc 45 ...
    (comp.lang.c)
  • Re: Questions about pointers to objects and pointers to functions
    ... >>> struct A { ... >> You might be asking about converting the object representation ... when compiler optimization is turned on). ...
    (comp.lang.c)
  • Re: Why are some types implemented as struct?
    ... converting it to a class, so now I just don't bother with them any more. ... You can change values in a struct as easily as you can in a class. ... The fact that structs are _copied_ rather than references leads to code that either doesn't work as expected, or just doesn't compile, or is more inconvenient than it could or should be. ...
    (microsoft.public.dotnet.languages.csharp)