Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

cost of Marshalling a large array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Iain - 05 Sep 2005 14:48 GMT
I have a C++ module which takes and returns parameters as (one and two D)
arrays of int and double.

I want to call this from c#, but I'm concerned about the memory
implications.  THe data items in question represent a sparse array which
may have many millions of entries.

The impression I have from the docs is that marshalling an array from clr
to C++ requires (at best) a bit copy.  This would effectively double the
amount of memory I would need which could be a serious problem.

Am I correct that there is a memory copy and is there any way of getting
round this?

Iain
Signature

Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk

Mattias Sjögren - 09 Sep 2005 20:16 GMT
Iain,

>The impression I have from the docs is that marshalling an array from clr
>to C++ requires (at best) a bit copy.  This would effectively double the
>amount of memory I would need which could be a serious problem.
>
>Am I correct that there is a memory copy and is there any way of getting
>round this?

An array of a blittable type such as int or double doesn't need to be
copied, it can simply be pinned for the duration of the native call.

If the C++ library returns an array in native memory, you either have
to copy it into a managed array or use C# unsafe code to use it.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.