473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Help on C# custom marshaling

Hello,

I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These model object could be large objects. Instead of transfering duplicate models I would like to marshal in the model id and when I retrieve the objects on the client side I will un marshal the model id and lookup the model from the cache.

I would appreciate it if anyone could tell me where I may be going wrong or give me tips on how to better debug this custom marshaling. Or maybe there is a better way to get this performance improvement without custom marshaling?

Thanks,
JP

[Serializable]
public abstract class ADDInfoDescriptor : IDDInfoDescriptor
{
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(DDMarshaler))]
private IDataDrivenModel ddModel = null;
...
}

// Class that has attribute being customed marshaled
[Serializable]
public class ClientInfoDescriptor : ADDInfoDescriptor
{
...
}

// Marshaling class
public sealed class DDMarshaler : System.Runtime.InteropServices.ICustomMarshaler
{
private static DDMarshaler marshaler = null;
public static ICustomMarshaler GetInstance(string cookie)
{
if (marshaler == null)
{
marshaler = new DDMarshaler();
}
return marshaler;
}

public DDMarshaler()
{
}

public object MarshalNativeToManaged(System.IntPtr pNativeData)
{
int id = Marshal.ReadInt32(pNativeData);
return DDModelCache.Instance.GetModel(id);
}

public System.IntPtr MarshalManagedToNative(object managedObj)
{
IDataDrivenModel ddModel = (IDataDrivenModel)managedObj;
IntPtr unmanagedArray = Marshal.AllocHGlobal(sizeof(Int32));
Marshal.WriteInt32(unmanagedArray, ddModel.ID);
return unmanagedArray;
}

public void CleanUpManagedData(object ManagedObj)
{
}

public int GetNativeDataSize()
{
return sizeof(Int32);
}

public void CleanUpNativeData(System.IntPtr pNativeData)
{
Marshal.FreeHGlobal(pNativeData);
}
}
Feb 13 '08 #1
0 1843

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Scott Dowd | last post by:
I need explicit example of how to use SetupDi* functions in both C# .NET and VB .NET to determine device interface detail for a given device class with interface information detail. All examples...
0
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. ...
4
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
3
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
1
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through...
3
by: Salvador | last post by:
Hi, I am using an old Win32 DLL that expects a LPBYTE as a parameter. The Stringbuilder appears to be working, the problem is that the component is sending me a string with NULL characters in the...
4
by: MSDousti | last post by:
Hi all, I read some Q&As in the Net, discussing Marshalization of nested structs in C# (or VB.NET). Some guys stated that .NET framework does not support this feature yet. Are they right? ...
2
by: Ryan Ross | last post by:
Hello, I need some help with the SendMessage method. I've imported it into C# with the following statement: public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, long wparam, int...
10
by: Jon | last post by:
I'm investiging multi-threaded GUI applications; specifically the technique used to ensure that controls are only modified under the correct thread. The standard technique is to use ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.