new

R

RedLars

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 :)
 
G

Giovanni Dicanio

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top