473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Collection problem in Managed C++

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!
Nov 17 '05 #1
5 1187
NotABug wrote:
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/de...vclrf__box.asp

-cd
Nov 17 '05 #2
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:
NotABug wrote:
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/de...vclrf__box.asp

-cd

Nov 17 '05 #3
NotABug wrote:
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
Nov 17 '05 #4
"NotABug" <No*****@discussions.microsoft.com> wrote:
Is it possible to do collections of struct __values in MC++ 2003?
see __box( )


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/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
Nov 17 '05 #5
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]" <no*****@microsoft.invalid> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
"NotABug" <No*****@discussions.microsoft.com> wrote:
> Is it possible to do collections of struct __values in MC++ 2003?

see __box( )
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/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

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to...
5
by: Laser Lu | last post by:
What doese Garbage Collection mean? And what is Managed Code? Any links to relevant articles or resources would be appreciated! -- Best regards, Laser Lu
2
by: Oculus | last post by:
Before I get into the question -- I know .NET isn't the right solution for this app but it's part of my clients requirements and writing this in C++ isn't an option. That being said -- my app is a...
1
by: Howard Weiss | last post by:
I would like to create a collection of managed objects - to be exact, instances of a form which I use to display images. This collection would be similar to the controls collection which is part...
2
by: Howard Weiss | last post by:
I am writing a Managed C++ application. In my application, I create a modeless sub-form using New. I retain a pointer to this sub-form in my application. If the user closes this form, my...
1
by: Russell Mangel | last post by:
Sorry about the Cross-Post, I posted my question in the wrong group. Hello, What is the simplest way to create a dynamic collection (during run-time), using basic C (Struct data types). Since...
1
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated...
6
by: Lee Crabtree | last post by:
Pinning a regular managed array is pretty easy in C++/CLI, such as: if buffer is defined thusly: array<System::Byte^buffer pinning it would be something like: pin_ptr<unsigned charpinBuf =...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.