473,378 Members | 1,495 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,378 software developers and data experts.

pin_ptr vs malloc for unmanaged array

_DS

My managed code needs to shuttle an unmanaged buffer between a couple
unmanaged functions. I know this could be done via pin_ptr, and I
understand the implications re managed heap fragmentation (I'll set it
up at the start of the program and leave it).

I believe that this could also be done by old-fashioned #include
<malloc.h> with standard allocators. Is there any reason to prefer
malloc over a pinned ptr?

Given that I may need to access the buffer in C#, I was leaning toward
a pinned pointer. Is there an advantage in Malloc that would outweigh
that?
Feb 21 '06 #1
1 1807
_DS wrote:
My managed code needs to shuttle an unmanaged buffer between a couple
unmanaged functions. I know this could be done via pin_ptr, and I
understand the implications re managed heap fragmentation (I'll set it
up at the start of the program and leave it).

I believe that this could also be done by old-fashioned #include
<malloc.h> with standard allocators. Is there any reason to prefer
malloc over a pinned ptr?

Given that I may need to access the buffer in C#, I was leaning toward
a pinned pointer. Is there an advantage in Malloc that would outweigh
that?


If you need to access the buffer from managed code then you must allocate it
on the managed heap and pin it for use by your unmanaged code.

-cd
Feb 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: roni | last post by:
hi. i have bug in my application that using managed c++ and unmanged dll (also vb.net involved). my question is about malloc , can i use malloc in the unmanaged part ? i just want to know...
2
by: T Ray Humphrey | last post by:
I could not get the following code to compile: public ref class wrapper { void Read(int^ mpLen) { pin_ptr<int> pLen = mpLen; unmanaged* punman = new unmanaged(); punman->Read(pLen); return; }
11
by: Tao.Young | last post by:
when i doing this: pin_ptr<A> pA = gcnew A; // assume A is a ref class i'll get many compiler errors. does anyone know how to do it correctly? Thanks in advance.
3
by: Nobody | last post by:
I posted this bug to MS, but was wondering if someone else could try inserting the following into a C++/cli project and seeing if it causes the compiler to barf: array<float,2>^ fMatrix = gcnew...
7
by: _iycrd | last post by:
Is there an easy way to pin a pointer that is a member of a class, and leave that pointer pinned for the duration of the class's existence? The pointer would presumably be pinned inside the class's...
1
by: Bruce | last post by:
public ref class GpsDevice abstract { /* Please note GarXface4::GpsDevice* is in a different namespace from this one and GarXface4::GpsDevice is an unmanaged class */ virtual...
7
by: David Lowndes | last post by:
I've got a project with a fair bit of mixed C++/CLI calling native code, often passing raw pointers - and I'm worrying that we may have occasions where we don't use pin_ptr when we need to. ...
9
by: =?Utf-8?B?U2hhcm9u?= | last post by:
In my managed code (C#) I have a some dozens of single dimension byte array. I get each of this arrays from another unmanaged code (first DLL). I need to stitch these arrays to a dual dimensions...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.