1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: memory 18.10.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov
13 *
14 * Summary: This file provides functionality for memory management.
15 *
16 ******************************************************************************/
17
18 #ifndef _MEMORY_
19 #define _MEMORY_
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif // __cplusplus
24
25 #include "types.h"
26
27 /*--------------------------------------------------------------------------
28 * Defines
29 */
30 #define MEM_EDGE 0xFFFF // Alloc from heap if the memory size
31 // is less or equal than MEM_EDGE
32 #define MEM_HEAPSIZE 0x40000 // The minimum size of the heap
33
34 typedef struct _heap
35 {
36 pvoid ptr; // Pointer to the heap memory
37 puint chain; // Array of ABC_COUNT free chains
38 uint size; // The summary memory size
39 uint remain; // The remain size of the heap
40 uint free; // The size of free blocks
41 // uint count; // The count of allocated blocks
42 // uint alloc; // The allocated size
43 } heap, * pheap;
44
45 typedef struct memory
46 {
47 pheap heaps; // Array of ABC_COUNT heaps
48 uint last; // The number of the latest active heap
49 puint sid; // Array of ABC_COUNT limits of block sizes
50 } memory;
51
52 extern pubyte _lower;
53 extern pubyte _bin;
54 extern pubyte _hex;
55 extern pubyte _dec;
56 extern pubyte _name;
57
58 /*--------------------------------------------------------------------------
59 The each memory block begins two bytes.
60 1. The number of heap ( from 0 to MAX_BYTE ).
61 2. The id of block size. The block doesn't belong to any heap if it equals
62 MAX_BYTE.
63 If the block is free then it contains the next free block with the same id.
64 */
65 //--------------------------------------------------------------------------
66
67 pvoid DLL_EXPORT STDCALL mem_alloc( uint size );
68 pvoid STDCALL mem_allocz( uint size );
69 pvoid DLL_EXPORT STDCALL mem_copy( pvoid dest, pvoid src, uint len );
70 void STDCALL mem_copyui( puint dest, puint src, uint len );
71 uint DLL_EXPORT STDCALL mem_copyuntilzero( pubyte dest, pubyte src );
72 uint STDCALL mem_deinit( void );
73 uint DLL_EXPORT STDCALL mem_free( pvoid ptr );
74 uint STDCALL mem_getsize( pvoid ptr );
75 uint STDCALL mem_init( void );
76 uint STDCALL mem_index( pubyte dest, uint number );
77 uint STDCALL mem_iseqzero( pvoid dest, pvoid src );
78 uint DLL_EXPORT STDCALL mem_len( pvoid data );
79 uint STDCALL mem_lensh( pvoid data );
80 void STDCALL mem_move( pvoid dest, pvoid src, uint len );
81 pvoid DLL_EXPORT STDCALL mem_zero( pvoid dest, uint len );
82 void STDCALL mem_zeroui( puint dest, uint len );
83 int STDCALL mem_cmp( pvoid dest, pvoid src, uint len );
84 int DLL_EXPORT STDCALL mem_cmpign( pvoid dest, pvoid src, uint len );
85 void STDCALL mem_swap( pubyte left, pubyte right, uint len );
86 //uint memtest();
87 //uint STDCALL memstat();
88 //extern uint bufnum;
89
90 //--------------------------------------------------------------------------
91
92 #ifdef __cplusplus
93 }
94 #endif // __cplusplus
95
96 #endif // _MEMORY_
Редактировать