473,856 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on C# custom marshaling

1 New Member
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 (ClientInfoDesc riptor) over a remote call. The objects all have a model object (IDataDrivenMod el) 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 ADDInfoDescript or : IDDInfoDescript or
{
[MarshalAs(Unman agedType.Custom Marshaler, MarshalTypeRef = typeof(DDMarsha ler))]
private IDataDrivenMode l ddModel = null;
...
}

// Class that has attribute being customed marshaled
[Serializable]
public class ClientInfoDescr iptor : ADDInfoDescript or
{
...
}

// Marshaling class
public sealed class DDMarshaler : System.Runtime. InteropServices .ICustomMarshal er
{
private static DDMarshaler marshaler = null;
public static ICustomMarshale r GetInstance(str ing cookie)
{
if (marshaler == null)
{
marshaler = new DDMarshaler();
}
return marshaler;
}

public DDMarshaler()
{
}

public object MarshalNativeTo Managed(System. IntPtr pNativeData)
{
int id = Marshal.ReadInt 32(pNativeData) ;
return DDModelCache.In stance.GetModel (id);
}

public System.IntPtr MarshalManagedT oNative(object managedObj)
{
IDataDrivenMode l ddModel = (IDataDrivenMod el)managedObj;
IntPtr unmanagedArray = Marshal.AllocHG lobal(sizeof(In t32));
Marshal.WriteIn t32(unmanagedAr ray, ddModel.ID);
return unmanagedArray;
}

public void CleanUpManagedD ata(object ManagedObj)
{
}

public int GetNativeDataSi ze()
{
return sizeof(Int32);
}

public void CleanUpNativeDa ta(System.IntPt r pNativeData)
{
Marshal.FreeHGl obal(pNativeDat a);
}
}
Feb 13 '08 #1
0 1881

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

Similar topics

5
6462
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 available on the web and/or Microsoft documentation are C or C++ based and do not take into account the various issues and pitfalls that the .NET based environment incurs, or otherwise avoids over unmanaged code, in short, no examples of how to...
0
1894
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. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
4
11712
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
3652
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
2488
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 CLI ( using a mixed mode DLL ) have any performance penalty? consider one Native C++ CLI assembly calling a methos od another CLI Native C++ Assembly, will there be any marshaling penalty, will there be any penelty at-all? is it possible to pass a...
3
4717
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 middle, and my StringBuilder is shrinking the message. Example StringBuilder buffer = new StringBuilder(255); Win32 sends : VB123421414\0\0\0\0HRA0021331 StringBuilder reads : VB123421414
4
3151
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? BTW, by nested structs I mean structures such as this:
2
8541
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 lparam);
10
3286
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 if(InvokeRequired == true) ... BeginInvoke(...) ... I have some code that ensures that an event fired from a worker (non-GUI) thread will use the appropriate BeginInvoke call for synchronisation. By offloading the synchronisation onto the worker thread the...
0
9764
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10699
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9535
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4580
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4176
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.