473,663 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managed arrays as unmanaged ptrs

Any know how to convert a managed array to an unmanaged array (ptr)?

// Managed
float[] f = new float [6];

// Unmanaged
unsafe
{
float *pArray = f; // No good

float *pArray = (float*) f; // Compiler still doesn't allow it
}

I'm assuming there might be some marshalling involved.

Also, are unsafe {} blocks the only way to combined managed and unmanaged
logic?

Sorry... I'm still pretty new to mixing managed and unmanaged code.
--
Bill Merrill
Lead Developer
Merchant Companion
http://www.merchantcompanion.com
Nov 17 '05 #1
2 1604
The first declaration you have is not of a managed array. Neither in VC
2002/2003 syntax, nor in VC 2005 syntax. And an unsafe" block is not C++,
but C#.

Are you sure you are posting in the right newsgroup?

Thanks.

Ronald Laeremans
Visual C++ team

"The unProfessional" <sp**@shitbits. com> wrote in message
news:uO******** ************@mp owercom.net...
Any know how to convert a managed array to an unmanaged array (ptr)?

// Managed
float[] f = new float [6];

// Unmanaged
unsafe
{
float *pArray = f; // No good

float *pArray = (float*) f; // Compiler still doesn't allow
it
}

I'm assuming there might be some marshalling involved.

Also, are unsafe {} blocks the only way to combined managed and unmanaged
logic?

Sorry... I'm still pretty new to mixing managed and unmanaged code.
--
Bill Merrill
Lead Developer
Merchant Companion
http://www.merchantcompanion.com

Nov 17 '05 #2
Sorry... It is a C# question.

"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote in message
news:u1******** *****@TK2MSFTNG P09.phx.gbl...
The first declaration you have is not of a managed array. Neither in VC
2002/2003 syntax, nor in VC 2005 syntax. And an unsafe" block is not C++,
but C#.

Are you sure you are posting in the right newsgroup?

Thanks.

Ronald Laeremans
Visual C++ team

"The unProfessional" <sp**@shitbits. com> wrote in message
news:uO******** ************@mp owercom.net...
Any know how to convert a managed array to an unmanaged array (ptr)?

// Managed
float[] f = new float [6];

// Unmanaged
unsafe
{
float *pArray = f; // No good

float *pArray = (float*) f; // Compiler still doesn't allow
it
}

I'm assuming there might be some marshalling involved.

Also, are unsafe {} blocks the only way to combined managed and unmanaged logic?

Sorry... I'm still pretty new to mixing managed and unmanaged code.
--
Bill Merrill
Lead Developer
Merchant Companion
http://www.merchantcompanion.com


Nov 17 '05 #3

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

Similar topics

1
741
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method (defined on a 'Global Functions' class) in the generated assembly with an export name of the form...
1
7225
by: Eric Hendriks | last post by:
// In an unmanaged DLL the following function must be called: // int VFGeneralize(const BYTE * const * features); // "features" parameter is supposed to be an array of byte arrays. // function is Marshaled as follows: static extern int VFGeneralize(byte features); In C# I have the following: // Allocate memory to store "Count" references to byte arrays
16
14116
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++ precisely into the passed byteArray, so that after the function has proceded the content of the...
6
2553
by: Omid Hodjati | last post by:
Hi All, I implemented an encryption algorithm using C#, native C++ and managed C++. Then I measured the CPU time used for executing this algorithm in all implementation. The managed version of C++ was the worst ! It is 20 times slower that the native version and 6 times slower that the C# versio !! Because i wanted to use automatic memory management offered by .Net framework, i used the managaed classes available. e.g. i have used...
7
8222
by: Klaus Bonadt | last post by:
I have an existing VC6 application using the MFC. I am able to pass CString and other parameters from such a VC6 dll to an unmanaged MFC dll (compiled in Visual Studio .NET). Now I want to use .Net functionality, i.e. calling methods in managed code. How do I pass CString variables for input and output usage, i.e. providing and retrieving char arrays? Regards, Klaus
7
7561
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it. Also, I was wondering could there be issues in not making copies when converting??? I was thinking, when "pointing" to the same data with both managed and unmanaged strings/arrays couldn't there be issues such as the garbage collector trying to...
3
3500
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust ------------------------------------------------------------------------
4
5668
by: Andreas Reiff | last post by:
Hi! I want some communication to take place between a c++ app and a c++ .dll with an intermediate managed/unmanaged c++ dll. Basicall, I want the unmanaged c++ dll to have a callback to the unmanaged c++ app. Also, the managed c++ part should call the c# dll. I don't mind about where the array is created, but I need to be able to pass it around. Anyhow, my problem is, that if I create an array in unmanaged c++ like
20
2295
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Sorry to bring up a topic that is just flogging a dead horse.... but... On the topic of memory management.... I am doing some file parcing that has to be done as quick as posible, but what I have found hasnt been encouraging... I found that the *quickest* way is to use a struct to retrieve fixed length packets out of the file, but structs get placed on the stack! In one of the books I read, the stack is only about 1mb, so I would...
0
8857
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
8768
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
8633
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
7368
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...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.