This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


The Problem with (Un)Boxing Operations



Download 21,46 Mb.
Pdf ko'rish
bet635/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   631   632   633   634   635   636   637   638   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

The Problem with (Un)Boxing Operations

Although boxing and unboxing are very convenient from a programmer’s point of view, this simpli-

fied approach to stack/heap memory transfer comes with the baggage of performance issues (in

both speed of execution and code size) and a lack of type safety. To understand the performance

issues, ponder the steps that must occur to box and unbox a simple integer:

1.

A new object must be allocated on the managed heap.



2.

The value of the stack-based data must be transferred into that memory location.



3.

When unboxed, the value stored on the heap-based object must be transferred back to the

stack.

4.

The now unused object on the heap will (eventually) be garbage collected.

Although the current Main() method won’t cause a major bottleneck in terms of performance,

you could certainly feel the impact if an ArrayList contained thousands of integers that are manip-

ulated by your program on a somewhat regular basis.

Now consider the lack of type safety regarding unboxing operations. As previously explained, to

unbox a value using the syntax of C#, you make use of the casting operator. However, the success or

failure of a cast is not known until 



runtime. Therefore, if you attempt to unbox a value into the

wrong data type, you receive an InvalidCastException:

static void Main(string[] args)

{

ArrayList myInts = new ArrayList();



myInts.Add(10);


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   631   632   633   634   635   636   637   638   ...   1830




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish