WWW.DISSERS.RU


...
    !

Pages:     | 1 |   ...   | 13 | 14 || 16 | 17 |   ...   | 21 |

p ayce popa pecp ceea cea (SS) yaae cea (SP) ycaaac a, o SS:SP yaae a ep a oce ceea cea. Pecp SS oa e eec o pe oe popa, a SP oe epeac , oa e oce oa ceea. Paep ceooo ceea e oe pea 64 ; paep o yoa 16 , o oe ee peo oopa {$M}.

yep oepee coyec caap oye Overlay xpae oepeoo oa. Paep oepeoo yepa o yoa cooecye paepy aoeo oepe popae; ec popae e oepee, paep yepa oepee pae 0. Paep yepa oepee oe yee c oo oa popa OvrSetBuf oy Overlay; o cyae paep y cooeceo yeaec, ceee epx HeapOrg.

ya xpa aece epeee, .e. epeee, pacpeeee epe o caapx poeyp New GetMem. ya aae c ac cooo a, ocaec oce apy popa. aec paep y ac o aoo acaoo ae y, oope oy ycaoe peo oopa $M. Paep y oa e ye ee aoo ae e pec acaoo. Ec ccee e a paoo aoy ae, popaa e ye oc. Maoe aee y o yoa pao 0 a, acaoe 640 ; o oaae, o o yoa ya ye aa c ocayc a.

paee ye ocyece oop y (oop ec ac oe pee oe Turbo Pascal).

MO H TO P ya ee ceoy cpyypy, pacyy o x apeco a ceee y. H paa y xpac epeeo HeapOrg, a epa y, cooecya e pae cooo a, xpac epeeo HeapPtr. a pa, oa aeca epeea pacpeeec ye (epe New GetMem), oop y epeae HeapPtr epx a paep o epeeo, ca aece epeee oy a pyo.

HeapPtr opayec oce ao oepa, ycaaa ceee aaoe o $0000 o $000F.

Maca paep epeeo, oop oe pacpeee ye, pae 65 519 a ($10 000 $000F), ocoy aa epeea oa ooc axoc oo ceee.

Oc o o e e a aece epeee, xpaec ye, yac o yx ye: (1) epe Dispose FreeMem (2) epe Mark Release. poce coco o c Mark Release, ec oe ceye oepaop:

New(Ptr1);

New(Ptr2);

Mark(P);

New(Ptr3);

New(Ptr4);

New(Ptr5);

cocoe y ye a, a a pc. 13.

Ptr1 H coepoe Ptr1^ Ptr2 paa a coepoe Ptr2^ Ptrcoepoe Ptr3^ Ptrcoepoe Ptr4^ Ptrcoepoe Ptr5^ HeapPtr Bepx paa HeapEnd a Pc. 13 Ocooee a c oo Mark Release Oepaop Mark(P) oeae cocoe y epe pacpeeee Ptr3 (coxpaee eyeo HeapPtr P).

Ec o oepaop Release(P), o cocoe y cae a a pc. 14, eo ocooa ce yaae, pacpeeee oce oa Mark.

PTR1 H H coepoe Ptr1^ paa Ptr2 a HeapPtr coepoe Ptr2^ Bepx HeapEnd paa a Pc. 14 Pacpeeee y oce oe Release(P) pueaue: Boee oepaopa Release(HeapOrg) ooc oae c yy, ocoy HeapOrg yaae a pay y.

popa, oope ocooa yaae ope, oo opao opy x pacpeee, poeyp Mark Release oe e. Oao oco popa pacpee ocooa yaae cya opao, o peye oee coo ex ypae, o peayec poeypa Dispose FreeMem. poeyp oo popae ocooa o yaae oe pe.

oa aeca epeea, oopa e ec ocee (epxe) ye, ocooaec c oo Dispose FreeMem, ya caoc paepoao. Ec a oea a e oceoaeoc oepaopo, a ae Dispose(Ptr3) cepee y oc pa (pc 15).

Ptr1 H coepoe Ptr1^ paa Ptr2 a coepoe Ptr2^ Ptrcoepoe Ptr4^ Ptr5 Bepx coepoe Ptr5^ paa HeapPtr a HeapEnd Pc. 15 "pa" ye Ec ceac o New(Ptr3), o o coa ae y e oac a. C pyo copo, oee Dispose(Ptr4) ye coo o, ocoy Ptr3 Ptr4 coce oa (pc. 16).

Ptr1 coepoe Ptr1^ H Ptr2 coepoe Ptr2^ paa a Ptr5 Bepx coepoe Ptr5^ paa HeapPtr a HeapEnd Pc. 16 eee coooo oa Haoe, oee Dispose(Ptr5) o-epx coac ee o coo o, a ae epeec HeapPtr . poe oo, o coo o coec co cooo a y, a a oce aa yaae ceac Ptr2 (pc. 17).

Ptr1 H paa a coepoe Ptr1^ Ptrcoepoe Ptr2^ HeapPtr Bepx paa HeapEnd a Pc.17 aee coooo oa ya ceac ao e coco, a a oce oe Release(P) (pc. 14). Oao, cooe o, coaaee papyaee o pee, cpoac oceyeo cooa.

C c o c o o x o o Apeca paep coox oo, coaaex Dispose FreeMem, xpac cce coox oo, oop pace cepxy o epxe pa ceea y. oa pacpeeec aeca epeea, o o paee ee ye poepec cco coox oo. Ec ec coo o oxoeo paepa (paep oe pae paepy pacpeeeoo oa), o o coyec.

peae: poeypa Release cea oae cco coox oo, o acae oop y "a" o cex coox oax, oope o e yaae y. Ec B ceaee o Mark Release c oa Dispose FreeMem, o B o yepe, o ax coox oo e cyecye.

epeea FreeList oy System yaae a ep coo o ye. o o coep yaae a cey coo o, oop coep yaae a cey coo o .. oce coo o coep yaae a epy y (.e. a ooee, yaaeoe HeapPtr). Ec cce coox oo e, FreeList paa HeapPtr.

opa epx 8 a coooo oa opeeec o TFreeRec:

type PFreeRec = ^TFreeRec;

TFreeRec = record Next : PFreeRec;

Size : Pointer;

end;

oe Next yaae a cey coo o, a o e ooee, o HeapPtr, ec o oce coo o. oe Size xpa paep coooo oa. aee Size e ooe 32-ooe aee; copee o opaoaoe aee yaae c co coox apapao (16-aox oo) cape coe co coox a (o 0 o 15) ae coe. Ceya y BlockSize peopaye aee o Size opaoe aee LongInt:

function BlockSize(Size: Pointer): Longint;

type PtrRec = record Lo, Hi: Word; end;

begin BlockSize := Longint(PtrRec(Size).Hi) * 16 + PtrRec(Size).Lo;

end;

o apapoa, o cea ye eco TFreeRec aae coooo oa, oop y opye paep AOO oa, pacpeeeoo New GetMem o 8-aoo pa. Ta oo, paepo 1..a pacpeeec 8 a, oo, paepo 9 16 pacpeeec 16 a .. o oe oaac pacoe cooae a eceoc ye a, ec a o ye paepo a. Oao, oo o e o paep ooce paep ecoyeoo pocpaca ee.

oee oo, o oe ao, 8-a oe paypoaoc apapye, o pacpeeee ocooee cyax oo eox paepo, a, apep, cpo c epeeo o popaax opao eca, e ye co paepoa yy. Hapep, oyc 50 -a o pacpeeec ocooaec, caoc eeo cce coox oo. o o ye opye o 56 a (7*8) ocey apoc a pacpeeee o 49 o 56 a ye ooc cooa o o, e oca o 1 o 7 a coo, oope yy paepoa yy.

e p e e a H e a p E r r o r epeea HeapError ooe ycao y opao oo y, oopa aec, oa oop y e oe opaoa apoc a pacpeeee a. HeapError yaae a y co cey aooo:

function HeapFunc(Size: Word): Integer; far;

pea oopa far ycaaae a oe oa y opao oo.

y opao ycaaaec pcaae ee apeca epeeo HeapError:

HeapError := @HeapFunc;

y opao oo y aec, oa New GetMem e oy opaoa apoc. apaep Size coep paep oa, oop e o pacpeee y opao oa oac ocoo o paepo e e oo.

B acoc o peyaa y opao opaae 0, 1 2. Bcyae 0 ye eeeo oa oa pee oe popae. B cyae 1 eco aapoo aepe popa New GetMem opaa yaae, pa Nil. Haoe, 2 oaae ycex oope apoc a pacpeeee a (oop oe o a y opao oo).

Caapa y opao oo y cea opaae 0, o po aapoy aepe popa, ec New GetMem e oy oe. ox popa ye yoa ceya y opao oo:

function HeapFunc(Size: Word): Integer; far;

begin HeapFunc := end;

oa a y ycaoea, New GetMem yy opaa nil p eoooc pacpee a, e po aapoy aepe popa.

peae. Bo y opao oo y c apaepo Size = 0 yaae, o yoeope apoca a pacpeeee oop y pacp yy, epea HeapPtr epx. o pocxo, oa e coox oo cce coox oo, oa ce cooe o co a apoca a pacpeeee. Bo c Size = 0 e yaae a oy, ocoy cyecye ocaooe eco pacpeee ey HeapPtr HeapEnd. Copee o yaae, o ecooaoe pocpaco HeapPtr o yeeo oop y oppye opaaeoe aee o oo oo a.

P a c p e e e e a C AMT POPAMM HA TPO C TPEETC ETPEX EE: PAMEEH EE POPAMMHOO OA, PAMEEH AHHX, HAMECOO COOBAH PEEPBPOBAH OMTOPOM HA BPEM BOHEH POPAMM (TA. 23).

23 PACPEEEH AMT B TPO Cu Ce ya Beop pepa DOS cape apeca a ae apeca a Oac a o o popa poecce pao ocaec eeo. Heeo ocaec a, ooa o caece ae. Oe a y ac o oo, coo a apaae popac c oo y alloc malloc.

Paep cooao a cea eec p aa aoaecx (oax) epeex yx, a ae a ce oo, o p oax y ce aocc apaep y.

MO E AM T C u poea: Bo ce epe pecpa ceeo (CS, DS, SS ES) acaec o o e apec. o o popa, caece ae, aec paeaee ae ce ooc 64 a. Taa oe aaae a aay cepee opae coyec oo ex cyax, oa ocoeo oyaec e a.

epeee a yaae ao oe a aa oo 2 aa (e yaae).

Ceoaeo, epeee a yaae coepa oo ceee yp cpoaoo ceea a.

Maea: o o popa ooc cee paepo 64 . Ce, ya caece ae paeac oo ceee paepo 64 . Taa oe a paec o yoa oxo ox aex cpex aa.

epeee a yaae ao a aa oo 2 aa (e yaae). Ceoaeo, epeee a yaae coepa ceee yp cpoaoo ceea a.

Cpe: Paep a o o popa opae 1 M. o oaae, o oe popa coyc aee yaae. Ce, ya caece ae, a cyae aeo oe a, paeac ece ceee a paepo 64 . Tay oe peoeyec pe p popapoa oe ox popa, e coyx ooo oea ax.

apeca (yaa) oe popa cya: aee yaae (cee ceee), aae aa.

Ta opao, ce o y oc a aee o, ce opa y cac ae. apeca ax coyc e yaae, aae 2 aa.

onama: o o popa ooc 64 . o ae ooc 1 M. Oe caecx ax opaaec 64 , a paep cea, a cex oee, e oe pec 64 .

Taa oe a oa pec p coa ax cpex o paepy popa, peyx ooo oea caecx ax.

Apeca yp popa oec c oo x yaaee (x paep 2 aa).

a ae Cooa Caece EPA Beo-a Hecoyea O o popa apeca ax coyc epexaoe aee yaae.

oa: Paep a o o popa opae 1 M. o caece ae ooc 64 . ya oe aa o 1 M a. Tay oe pxoc cooa o ox ox aaax.

a popaa, a ae apecyc ae yaae, aa 4 aa. B oo oe a oa oea ea ax e oe pea 64 .

Opoa: Aaoa oo oe, o cyap oe caecx ax oe pea 64 .

Opoa oe a e peycapae opox yaaee. Bce yaae Typo C oo pco eoac apec a y eoo a. apapyec, o o apec e coaae c o apeco, ye cooa ccee. Tao apec aaec ye apeco aco peec a opae aecx cpyypax.

Be paccapa ceyee ocae:

int *x;

*x=16;

o apecy, aaaeoy x, acaec co 16.

oop peeppye a, eoxoy xpae apeca (2 aa aeo oe).

Pages:     | 1 |   ...   | 13 | 14 || 16 | 17 |   ...   | 21 |



2011 www.dissers.ru -

, .
, , , , 1-2 .