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



Download 21,46 Mb.
Pdf ko'rish
bet794/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   790   791   792   793   794   795   796   797   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition



Source Code

The CustomConversions project is located under the Chapter 12 subdirectory.



Working with Pointer Types

In Chapter 4, you learned that the .NET platform defines two major categories of data: value types

and reference types. Truth be told, however, there is a third category: 

pointer types. To work with

pointer types, we are provided with specific operators and keywords that allow us to bypass the

CLR’s memory management scheme and take matters into our own hands (see Table 12-3).

Table 12-3.

Pointer-Centric C# Operators and Keywords

Operator/Keyword

Meaning in Life

*

This operator is used to create a pointer variable (i.e., a variable that



represents a direct location in memory). As in C(++), this same operator is

used for pointer indirection.

&

This operator is used to obtain the address of a variable in memory.



->

This operator is used to access fields of a type that is represented by a pointer

(the unsafe version of the C# dot operator).

[]

The [] operator (in an unsafe context) allows you to index the slot pointed to



by a pointer variable (recall the interplay between a pointer variable and the

[] operator in C(++)!).

++, --

In an unsafe context, the increment and decrement operators can be applied



to pointer types.

+, -


In an unsafe context, the addition and subtraction operators can be applied

to pointer types.

==, !=, <, >, <=, =>

In an unsafe context, the comparison and equality operators can be applied

to pointer types.

stackalloc

In an unsafe context, the stackalloc keyword can be used to allocate C#

arrays directly on the stack.

fixed

In an unsafe context, the fixed keyword can be used to temporarily fix a



variable so that its address may be found. 

Now, before we dig into the details, let me point out the fact that you will 



seldom if ever need to

make use of pointer types. Although C# does allow you to drop down to the level of pointer manipu-

lations, understand that the .NET runtime has absolutely no clue of your intentions. Thus, if you

mismanage a pointer, you are the one in charge of dealing with the consequences. Given these

warnings, when exactly would you need to work with pointer types? There are two common

situations:

• You are looking to optimize select parts of your application by directly manipulating mem-

ory outside the management of the CLR.

• You are calling methods of a C-based *.dll or COM server that demand pointer types as

parameters. Even in this case, you can often bypass the use of pointer types in favor of the

System.IntPtr type and members of the System.Runtime.InteropServices.Marshal type.

C H A P T E R   1 2  




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   790   791   792   793   794   795   796   797   ...   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