Connecting Tech Pros Worldwide Forums | Help | Site Map

new

RedLars
Guest
 
Posts: n/a
#1: Sep 10 '08
Hi,

In a mix-mode dynamic library I perform the following code;

public __gc class foo
{
public:
void bar()
{
ULONG * array = new ULONG[10];
}
}

The array pointer will at some point be paaed to an unmanaged method.
Will the new operator in the above context always create a unmanaged
ULONG pointer?

Cheers :)

Giovanni Dicanio
Guest
 
Posts: n/a
#2: Sep 10 '08

re: new



"RedLars" <Liverpool1892@gmail.comha scritto nel messaggio
news:0a032251-0390-46ad-8e49-0f91b812c6e0@m45g2000hsb.googlegroups.com...
Quote:
In a mix-mode dynamic library I perform the following code;
>
public __gc class foo
{
public:
void bar()
{
ULONG * array = new ULONG[10];
}
}
>
The array pointer will at some point be paaed to an unmanaged method.
Will the new operator in the above context always create a unmanaged
ULONG pointer?
Yes, if you want a managed (garbage collected) array, you should use gcnew.

Note that the unmanaged pointer created with new[] must be properly deleted
using delete[].

Have you considered using more modern method to allocate arrays in native
C++, like using std::vector ?

e.g.

std::vector< ULONG array(10);

ULONG * ptr = &array[0];

// array automatically cleaned thanks to std::vector destructor

HTH,
Giovanni



Closed Thread