C# 0 The Complete Reference


System.StackOverflowException



Download 4,07 Mb.
Pdf ko'rish
bet751/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   747   748   749   750   751   752   753   754   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

System.StackOverflowException

 is thrown. Finally, 



stackalloc

can be used only in an unsafe context.

Normally, memory for objects is allocated from the 

heap,

 which is a region of free memory. 

Allocating memory from the stack is the exception. Variables allocated on the stack are not 

garbage-collected. Rather, they exist only while the method in which they are declared is 

executing. When the method is left, the memory is freed. One advantage to using 

stackalloc

 is 


that you don’t need to worry about the memory being moved about by the garbage collector.

Here is an example that uses 



stackalloc

:

// Demonstrate stackalloc.



using System;

class UseStackAlloc {

  unsafe static void Main() {

    int* ptrs = stackalloc int[3];

    ptrs[0] = 1;

    ptrs[1] = 2;

    ptrs[2] = 3;

    for(int i=0; i < 3; i++)

      Console.WriteLine(ptrs[i]);

  }


}

The output is shown here:

1

2

3




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   747   748   749   750   751   752   753   754   ...   1096




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