.


:




:

































 

 

 

 





HeapCompact , , . HeapValidate . HeapWalk , GetProcessHeaps .

HeapLock HeapUnlock , 8.

, Windows 9x Windows . , , 16- . , , , .

:

:

1. , Create GetProcessHeap.

2. , HeapAlloc.

3. HeapFree.

4. HeapDestroy.

. 5.2 5.2.

, , . , , malloc HeapAlloc, realloc HeapReAlloc, free HeapFree. calloc , HeapAlloc. HeapSize .

:

, , . , .

sortBT ( 5.1) UNIX- sort . (node heap), . , (data heap). , , . , .

8 , . , ( 5.4 5.5), , .

. 5.2. , , , . , , , . 5.1 , , , .

Windows, , . , . , ; , .

. 5.2.

 

5.1 , , .

, .

, , , .

, .

Windows, , 5.1, , . ( 3 ); . Win64 .

5.1 : FillTree, InsertTree, Scan TreeCompare. 5.2.

. , HEAP_GENERATE_EXCEPTIONS , , .

5.1. sortBT:

/* 5. sortBT. , .*/

#include "EvryThng.h"

#define KEY_SIZE 8

 

typedef struct _TreeNode {/* . */

struct _TreeNode *Left, *Right;

TCHAR Key[KEY_SIZE];

LPTSTR pData;

} TREENODE, *LPTNODE, **LPPTNODE;

#define NODE_SIZE sizeof(TREENODE)

#define NODE_HEAP_ISIZE 0x8000

#define DATA_HEAP_ISIZE 0x8000

#define MAX_DATA_LEN 0x1000

#define TKEY_SIZE KEY_SIZE * sizeof(TCHAR)

 

LPTNODE FillTree(HANDLE, HANDLE, HANDLE);

BOOL Scan(LPTNODE);

int KeyCompare (LPCTSTR, LPCTSTR); iFile;

 

BOOL InsertTree (LPPTNODE, LPTNODE);

 

int _tmain(int argc, LPTSTR argv[]) {

HANDLE hIn, hNode = NULL, hData = NULL;

LPTNODE pRoot;

CHAR ErrorMessage[256];

int iFirstFile = Options(argc, argv, _T("n"), &NoPrint, NULL);

/* , . */

for (iFile = iFirstFile; iFile < argc; iFile++) __try {

/* . */

hIn = CreateFile(argv[iFile], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

if (hIn == INVALID_HANDLE_VALUE) RaiseException(0, 0, 0, NULL);

__try { /* . */

hNode = HeapCreate(HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE, NODE_HEAP_ISIZE, 0);

hData = HeapCreate(HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE, DATA_HEAP_ISIZE, 0);

/* , . */

pRoot = FillTree(hIn, hNode, hData);

/* . */

_tprintf(_T(" : %s\n"), argv [iFile]);

Scan(pRoot);

} _ finally { /* .

/* . */

if (hNode!=NULL) HeapDestroy (hNode);

if (hNode!= NULL) HeapDestroy (hData);

hNode = NULL;

hData = NULL;

if (hIn!= INVALID_HANDLE_VALUE) CloseHandle (hIn);

}

} /* try-. */

__except(EXCEPTION_EXECUTE_HANDLER) {

_stprintf(ErrorMessage, _T("\n%s %s"), _T("sortBT, :"), argv [iFile]);

ReportError(ErrorMessage, 0, TRUE);

}

return 0;

}

5.2 , . , FillTree, . , KeyCompare, . , FillTree KeyCompare 5.1, . , , , .





:


: 2015-09-20; !; : 624 |


:

:

- , .
==> ...

1552 - | 1356 -


© 2015-2024 lektsii.org - -

: 0.014 .