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 } heap, * pheap;
42
43 typedef struct memory
44 {
45 pheap heaps; // Array of ABC_COUNT heaps
46 uint last; // The number of the latest active heap
47 puint sid; // Array of ABC_COUNT limits of block sizes
48 } memory;
49
50 extern pubyte _lower;
51 extern pubyte _bin;
52 extern pubyte _hex;
53 extern pubyte _dec;
54 extern pubyte _name;
55
56 /*--------------------------------------------------------------------------
57 The each memory block begins two bytes.
58 1. The number of heap ( from 0 to MAX_BYTE ).
59 2. The id of block size. The block doesn't belong to any heap if it equals
60 MAX_BYTE.
61 If the block is free then it contains the next free block with the same id.
62 */
63 //--------------------------------------------------------------------------
64
65 pvoid DLL_EXPORT STDCALL mem_alloc( uint size );
66 pvoid STDCALL mem_allocz( uint size );
67 pvoid DLL_EXPORT STDCALL mem_copy( pvoid dest, pvoid src, uint len );
68 void STDCALL mem_copyui( puint dest, puint src, uint len );
69 uint DLL_EXPORT STDCALL mem_copyuntilzero( pubyte dest, pubyte src );
70 uint STDCALL mem_deinit( void );
71 uint DLL_EXPORT STDCALL mem_free( pvoid ptr );
72 uint STDCALL mem_getsize( pvoid ptr );
73 uint STDCALL mem_init( void );
74 uint STDCALL mem_index( pubyte dest, uint number );
75 uint STDCALL mem_iseqzero( pvoid dest, pvoid src );
76 uint DLL_EXPORT STDCALL mem_len( pvoid data );
77 uint STDCALL mem_lensh( pvoid data );
78 void STDCALL mem_move( pvoid dest, pvoid src, uint len );
79 pvoid DLL_EXPORT STDCALL mem_zero( pvoid dest, uint len );
80 void STDCALL mem_zeroui( puint dest, uint len );
81 int STDCALL mem_cmp( pvoid dest, pvoid src, uint len );
82 int DLL_EXPORT STDCALL mem_cmpign( pvoid dest, pvoid src, uint len );
83 void STDCALL mem_swap( pubyte left, pubyte right, uint len );
84 //uint STDCALL memstat();
85 //extern uint bufnum;
86
87 //--------------------------------------------------------------------------
88
89 #ifdef __cplusplus
90 }
91 #endif // __cplusplus
92
93 #endif // _MEMORY_
Edit