473,396 Members | 1,843 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.

Can Managed C++ Eliminate Boxing/UnBoxing Overhead?

I want to be able to make my .NET applications run
just as fast as unmanaged C++. From my currently
somewhat limited understanding of the .NET framework
and the C# language, it seems that Boxing/Unboxing
might present of problem. Since C++ has pointer syntax,
I was thinking that this might eliminate the need for
Boxing and Unboxing. Am I right?

One of the things that my application needs is something
exactly like std::vector<unsigned int>. In C++ this has
the same performance as an array of "int". Is there
something like this in C#, or can I use managed C++
and a std::vector of managed memory?

Nov 17 '05 #1
4 2936
Peter Olcott wrote:
I want to be able to make my .NET applications run
just as fast as unmanaged C++. From my currently
somewhat limited understanding of the .NET framework
and the C# language, it seems that Boxing/Unboxing
might present of problem. Since C++ has pointer syntax,
I was thinking that this might eliminate the need for
Boxing and Unboxing. Am I right?

One of the things that my application needs is something
exactly like std::vector<unsigned int>. In C++ this has
the same performance as an array of "int". Is there
something like this in C#, or can I use managed C++
and a std::vector of managed memory?


You are right that boxing may be one of the points where the performance
of your .NET app suffers, but AFAIK you can't change that by using
(managed) C++ as a language. C# can use pointers in unsafe code and
managed C++ doesn't have anything else than that to offer either. The
issue of boxing doesn't have anything to do with which language you are
using.

The STL collection sample you give makes use of C++ templates to provide
for typed collections. You are correct in assuming that typed collections
will get rid of boxing overhead - you can do the exact same thing with
..NET Generics in .NET 2 (constructs like List<uint>). I'm lacking the
experience with managed C++ to say whether or not it's possible to make
use of C++ templates in managed code - I guess it might be possible
because C++ templates are a compiler feature, as opposed to .NET Generics,
which are a runtime feature. Given the choice, I'd opt for Generics of
course, if only for compatibility with other .NET languages.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2
Peter Olcott wrote:
I want to be able to make my .NET applications run
just as fast as unmanaged C++. From my currently
somewhat limited understanding of the .NET framework
and the C# language, it seems that Boxing/Unboxing
might present of problem. Since C++ has pointer syntax,
I was thinking that this might eliminate the need for
Boxing and Unboxing. Am I right?

One of the things that my application needs is something
exactly like std::vector<unsigned int>. In C++ this has
the same performance as an array of "int". Is there
something like this in C#, or can I use managed C++
and a std::vector of managed memory?


You are right that boxing may be one of the points where the performance
of your .NET app suffers, but AFAIK you can't change that by using
(managed) C++ as a language. C# can use pointers in unsafe code and
managed C++ doesn't have anything else than that to offer either. The
issue of boxing doesn't have anything to do with which language you are
using.

The STL collection sample you give makes use of C++ templates to provide
for typed collections. You are correct in assuming that typed collections
will get rid of boxing overhead - you can do the exact same thing with
..NET Generics in .NET 2 (constructs like List<uint>). I'm lacking the
experience with managed C++ to say whether or not it's possible to make
use of C++ templates in managed code - I guess it might be possible
because C++ templates are a compiler feature, as opposed to .NET Generics,
which are a runtime feature. Given the choice, I'd opt for Generics of
course, if only for compatibility with other .NET languages.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #3
"Peter Olcott" <ol****@att.net> wrote in message
news:VGgRe.6139$UI.719@okepread05...
I want to be able to make my .NET applications run
just as fast as unmanaged C++.
Good luck ;)
From my currently
somewhat limited understanding of the .NET framework
and the C# language, it seems that Boxing/Unboxing
might present of problem. Since C++ has pointer syntax,
I was thinking that this might eliminate the need for
Boxing and Unboxing. Am I right?
Boxing is an overhead, no doubt about it, and given that C# has autoboxing
instead of manual boxing it can happen when you don't expect it. If you want
to spend time optimising, just write your own collection that doesn't box
anything. C# has pointers too if you really want to use them. I was writing
a numerical algorithm a few years ago in C# and used pointer arithmetic to
get faster data access. I also pinned and passed managed arrays to native
C++ code for the really nasty stuff.

One of the things that my application needs is something
exactly like std::vector<unsigned int>. In C++ this has
the same performance as an array of "int". Is there
something like this in C#, or can I use managed C++
and a std::vector of managed memory?


You can use std::vectors for managed data, but there's really no need to.
Writing your own none boxing collection in v1.1 of the framework is trivial.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #4
"Peter Olcott" <ol****@att.net> wrote in message
news:VGgRe.6139$UI.719@okepread05...
I want to be able to make my .NET applications run
just as fast as unmanaged C++.
Good luck ;)
From my currently
somewhat limited understanding of the .NET framework
and the C# language, it seems that Boxing/Unboxing
might present of problem. Since C++ has pointer syntax,
I was thinking that this might eliminate the need for
Boxing and Unboxing. Am I right?
Boxing is an overhead, no doubt about it, and given that C# has autoboxing
instead of manual boxing it can happen when you don't expect it. If you want
to spend time optimising, just write your own collection that doesn't box
anything. C# has pointers too if you really want to use them. I was writing
a numerical algorithm a few years ago in C# and used pointer arithmetic to
get faster data access. I also pinned and passed managed arrays to native
C++ code for the really nasty stuff.

One of the things that my application needs is something
exactly like std::vector<unsigned int>. In C++ this has
the same performance as an array of "int". Is there
something like this in C#, or can I use managed C++
and a std::vector of managed memory?


You can use std::vectors for managed data, but there's really no need to.
Writing your own none boxing collection in v1.1 of the framework is trivial.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #5

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

Similar topics

43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
6
by: Justine | last post by:
Hi All, I need a small clarification with regard to Boxing. struct Currency { ......... } Currency Bal = new Currency; Object Obj = Bal;
0
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
8
by: Peter Olcott | last post by:
Exactly why does C# and .NET require all the extra copying of data?
94
by: Peter Olcott | last post by:
How can I create an ArrayList in the older version of .NET that does not require the expensive Boxing and UnBoxing operations? In my case it will be an ArrayList of structures of ordinal types. ...
19
by: ahjiang | last post by:
hi there,, what is the real advantage of boxing and unboxing operations in csharp? tried looking ard the internet but couldnt find any articles on it. appreciate any help
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
20
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Sorry to bring up a topic that is just flogging a dead horse.... but... On the topic of memory management.... I am doing some file parcing that has to be done as quick as posible, but what I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.