Collection problem in Managed C++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to do collections of struct __values in MC++ 2003?

How can I translate the following C# example to C++:

public sealed class PointsCollection : CollectionBase
{
public void Insert(int index, Point value)
{
List.Insert(index, value);
owner.UpdateRegion();
}
...

The compiler tells me there is no convertion from Point* to Object*.

What can I do?

Any help will be really appreciated!
 
NotABug said:
Is it possible to do collections of struct __values in MC++ 2003?

How can I translate the following C# example to C++:

public sealed class PointsCollection : CollectionBase
{
public void Insert(int index, Point value)
{
List.Insert(index, value);
owner.UpdateRegion();
}
...

The compiler tells me there is no convertion from Point* to Object*.

What can I do?

see __box( )

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrf__box.asp

-cd
 
Thanks. But I think that would create a lot of overhead no?
For any manipulation, the structure seems to be copied bytewise in and out
of the CLR memory..... but maybe is the only way...

The Mother of all questions is:

What would be the best way in terms of performance for storing big collections
of small data structures in Managed C++, like Colors or Points?

How would you do?

An indexed property to __value types maybe is the best option no?
Maybe implemented internally in STL...

what do you think?

Thanks
 
NotABug said:
Thanks. But I think that would create a lot of overhead no?
For any manipulation, the structure seems to be copied bytewise in
and out
of the CLR memory..... but maybe is the only way...

That's what C# does too, it just hides it from you. The overheads in
accessing a .NET collection from MC++ are no different than they are from
C#, you're just more aware of them.

-cd
 
NotABug said:
Thanks. But I think that would create a lot of overhead no?
For any manipulation, the structure seems to be copied bytewise in and out
of the CLR memory..... but maybe is the only way...

What would be the best way in terms of performance for storing big collections
of small data structures in Managed C++, like Colors or Points?

If you wish to expose a collection of value types to other .NET
applications, you have two choices:

1. Use an array. Arrays of value types use internal storage, and so are more
space- and time-efficient for small types. To learn more about this option,
take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguinet/html/drguinet6_update.asp

2. Use boxing, as Carl suggested. For more complex data structures, the
overhead of the data structure may exceed the overhead of the boxing in any
case.

On the other hand, if the collection is entirely internal to your
application, you'll probably get the best performance out of STL containers,
which specialize their implementations to your value types. You could even
wrap an STL container in a public managed class to form a restricted
interface to your collection for other .NET applications.

If none of these approaches seem to apply to you, could you give some more
information about your specific situation, such as the type of container you
need and whether you intend to share it? I hope this helps.
 
Oops, I used the wrong reply-to address in the below reply. This message has
a correct one. Sorry about that.
 
Back
Top