Need help with Managed arrays in C++... 
Author Message
 Need help with Managed arrays in C++...

I'm re-writing a DLL in managed C++ which holds multiple
vectors (arrays) of floating point data (Single).  In 6.0
with MFC I used to do this:

class CCommonDataFile : public CObject
{
  ....
private:
  CTypedPtrArray<CPtrArray, float*> m_dataColumnArray;
  ....

Quote:
}

so I'd have an array of pointers to float (float vectors)
and would just allocate a block of memory on the heap for
them and read in data from a file.  I'm really puzzled
with Managed arrays in C++.  How can I get the same
effect?  Is there some way to create, say, a managed array
of managed arrays of Singles??  Or a managed array of
pointers to managed arrays of Singles?  It seemed so much
simpler in the old C++...

Mark.



Sat, 19 Nov 2005 22:37:59 GMT  
 Need help with Managed arrays in C++...

--------------------
| Content-Class: urn:content-classes:message


| Subject: Need help with Managed arrays in C++...
| Date: Tue, 3 Jun 2003 07:37:59 -0700
| Lines: 22

| MIME-Version: 1.0
| Content-Type: text/plain;
|       charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcMp3br6YLm4ouxBRj2ojj/4YZGL0g==
| Newsgroups: microsoft.public.dotnet.languages.vc
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:24547
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| I'm re-writing a DLL in managed C++ which holds multiple
| vectors (arrays) of floating point data (Single).  In 6.0
| with MFC I used to do this:
|
| class CCommonDataFile : public CObject
| {
|   ....
| private:
|   CTypedPtrArray<CPtrArray, float*> m_dataColumnArray;
|   ....
| }
|
| so I'd have an array of pointers to float (float vectors)
| and would just allocate a block of memory on the heap for
| them and read in data from a file.  I'm really puzzled
| with Managed arrays in C++.  How can I get the same
| effect?  Is there some way to create, say, a managed array
| of managed arrays of Singles??  Or a managed array of
| pointers to managed arrays of Singles?  It seemed so much
| simpler in the old C++...
|
| Mark.
|

If you want to have a two dimension managed array of Single this is how you
declare one:
Single arr[,]= new Single[3,5];

If you want an array of array, or a jagged array you can not define one in
the current version of VC++. However you can workaround this limitation
using an array of System::Array objects like in the following sample:
        Array* arr[] = new Array*[5];
        arr[0] = new Single[5];
        arr[1] = new Single[3];
        arr[0]->SetValue( __box(Single(10)), 4);
        Console::WriteLine(arr[0]->Length);
        Console::WriteLine(arr[1]->Length);
        Console::WriteLine(arr[0]->GetValue(4)->ToString());
        Console::WriteLine(arr[0]->GetValue(4)->GetType()->ToString());

We are looking into supporting jagged arrays in managed C++ in the next
version of the product.
Hope it helps,
--
Silviu Guea, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.



Sun, 20 Nov 2005 01:44:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Really Easy Help needed Managed c++ syntax for declaring array of unsigned long

2. Managed array of managed arrays of char

3. help needed with Managed C++

4. Need help serializing object in managed c++

5. Need help with managed C++ calling C# assembly

6. marshal an array from managed C++ to unmanaged C++

7. return an array from unmanaged C++ to managed C++

8. Point array in managed C++?

9. Static Arrays, Initializers, Managed C++

10. Calling Managed C++ function from C# with array parameters

11. Returning arrays with managed C++ for use with COM

12. moving arrays from un-managed to managed code.

 

 
Powered by phpBB® Forum Software