new

  • Thread starter Thread starter RedLars
  • Start date Start date
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 :)
 
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
 
Back
Top