Connecting Tech Pros Worldwide Help | Site Map

Collection problem in Managed C++

NotABug
Guest
 
Posts: n/a
#1: Nov 17 '05
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!
Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a
#2: Nov 17 '05

re: Collection problem in Managed C++


NotABug wrote:[color=blue]
> 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?[/color]

see __box( )

http://msdn.microsoft.com/library/de...vclrf__box.asp

-cd


NotABug
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Collection problem in Managed C++


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

"Carl Daniel [VC++ MVP]" wrote:
[color=blue]
> NotABug wrote:[color=green]
> > 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?[/color]
>
> see __box( )
>
> http://msdn.microsoft.com/library/de...vclrf__box.asp
>
> -cd
>
>
>[/color]
Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a
#4: Nov 17 '05

re: Collection problem in Managed C++


NotABug wrote:[color=blue]
> 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...[/color]

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


Derrick Coetzee [MSFT]
Guest
 
Posts: n/a
#5: Nov 17 '05

re: Collection problem in Managed C++


"NotABug" <NotABug@discussions.microsoft.com> wrote:[color=blue][color=green][color=darkred]
> > > Is it possible to do collections of struct __values in MC++ 2003?[/color]
> >
> > see __box( )[/color]
>
> 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[/color]
collections[color=blue]
> of small data structures in Managed C++, like Colors or Points?[/color]

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/de...et6_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.
--
Derrick Coetzee, Microsoft Speech Server developer
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included code samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


Derrick Coetzee [MSFT]
Guest
 
Posts: n/a
#6: Nov 17 '05

re: Collection problem in Managed C++


Oops, I used the wrong reply-to address in the below reply. This message has
a correct one. Sorry about that.
--
Derrick Coetzee, Microsoft Speech Server developer
This posting is provided "AS IS" with no warranties, and confers no rights.

"Derrick Coetzee [MSFT]" <noreply@microsoft.invalid> wrote in message
news:Ozaaii39EHA.2180@TK2MSFTNGP10.phx.gbl...[color=blue]
> "NotABug" <NotABug@discussions.microsoft.com> wrote:[color=green][color=darkred]
> > > > Is it possible to do collections of struct __values in MC++ 2003?
> > >
> > > see __box( )[/color]
> >
> > Thanks. But I think that would create a lot of overhead no?
> > For any manipulation, the structure seems to be copied bytewise in and[/color][/color]
out[color=blue][color=green]
> > of the CLR memory..... but maybe is the only way...
> >
> > What would be the best way in terms of performance for storing big[/color]
> collections[color=green]
> > of small data structures in Managed C++, like Colors or Points?[/color]
>
> 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[/color]
more[color=blue]
> space- and time-efficient for small types. To learn more about this[/color]
option,[color=blue]
> take a look at
>[/color]
http://msdn.microsoft.com/library/de...et6_update.asp[color=blue]
>
> 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[/color]
any[color=blue]
> case.
>
> On the other hand, if the collection is entirely internal to your
> application, you'll probably get the best performance out of STL[/color]
containers,[color=blue]
> 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[/color]
you[color=blue]
> need and whether you intend to share it? I hope this helps.
> --
> Derrick Coetzee, Microsoft Speech Server developer
> This posting is provided "AS IS" with no warranties, and confers no[/color]
rights.[color=blue]
> Use of included code samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm[/color]


Closed Thread