Tesseract 3.01
|
00001 /********************************************************************** 00002 * File: memry.h (Formerly memory.h) 00003 * Description: Header file for basic memory allocation/deallocation. 00004 * Author: Ray Smith 00005 * Created: Tue May 8 16:03:48 BST 1990 00006 * 00007 * (C) Copyright 1990, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef MEMRY_H 00021 #define MEMRY_H 00022 00023 #include <stddef.h> 00024 #include "host.h" 00025 00026 #define JUSTCHECKS 0 /*just check consistency */ 00027 #define MEMCHECKS 1 /*report totals */ 00028 #define FULLMEMCHECKS 2 /*report on all blocks */ 00029 00030 /********************************************************************** 00031 * ALLOC_2D_ARRAY 00032 * DEPRECATED! Use GENERIC_2D_ARRAY instead. 00033 * Create a dynamic 2D array. 00034 **********************************************************************/ 00035 00036 #define ALLOC_2D_ARRAY(x,y,mem,ptrs,type) /*make 2d array*/\ 00037 { \ 00038 inT32 TMP_i; \ 00039 mem=(type*)alloc_mem((x)*(y)*sizeof(type)); /*get memory*/\ 00040 ptrs=(type**)alloc_mem((x)*sizeof(type*)); /*get ptrs*/\ 00041 for (TMP_i=0;TMP_i<(x);TMP_i++)\ 00042 ptrs[TMP_i]=mem+(y)*TMP_i; /*set ptrs*/\ 00043 } \ 00044 00045 /********************************************************************** 00046 * FREE_2D_ARRAY 00047 * 00048 * Destroy a 2D array created by ALLOC_2D_ARRAY 00049 **********************************************************************/ 00050 00051 #define FREE_2D_ARRAY(mem,ptrs) /*free a 2D array*/\ 00052 { \ 00053 free_mem(mem); /*free the memory*/\ 00054 free_mem(ptrs); /*and the ptrs*/\ 00055 } \ 00056 00057 /********************************************************************** 00058 * ALLOC_BIG_2D_ARRAY 00059 * 00060 * Create a dynamic 2D array. Use a memory allocator that allows 00061 * allocation of bigger chunks. 00062 **********************************************************************/ 00063 00064 #define ALLOC_BIG_2D_ARRAY(x,y,mem,ptrs,type) /*make 2d array*/\ 00065 { \ 00066 inT32 TMP_i; \ 00067 mem=(type*)alloc_big_mem((x)*(y)*sizeof(type)); /*get memory*/\ 00068 ptrs=(type**)alloc_big_mem((x)*sizeof(type*)); /*get ptrs*/\ 00069 for (TMP_i=0;TMP_i<(x);TMP_i++)\ 00070 ptrs[TMP_i]=mem+(y)*TMP_i; /*set ptrs*/\ 00071 } \ 00072 00073 /********************************************************************** 00074 * FREE_BIG_2D_ARRAY 00075 * 00076 * Destroy a 2D array created by ALLOC_BIG_2D_ARRAY 00077 **********************************************************************/ 00078 00079 #define FREE_BIG_2D_ARRAY(mem,ptrs) /*free a 2D array*/\ 00080 { \ 00081 free_big_mem(mem); /*free the memory*/\ 00082 free_big_mem(ptrs); /*and the ptrs*/\ 00083 } \ 00084 00085 extern DLLSYM void check_mem( //check consistency 00086 const char *string, //context message 00087 inT8 level //level of check 00088 ); 00089 //allocate string 00090 extern DLLSYM char *alloc_string(inT32 count //no of chars required 00091 ); 00092 extern DLLSYM void free_string( //free a string 00093 char *string //string to free 00094 ); 00095 //allocate memory 00096 extern DLLSYM void *alloc_struct ( 00097 inT32 count, //no of chars required 00098 const char *name = NULL //class name 00099 ); 00100 extern DLLSYM void free_struct ( //free a structure 00101 void *deadstruct, //structure to free 00102 inT32 count, //no of bytes 00103 const char *name = NULL //class name 00104 ); 00105 extern DLLSYM void *alloc_mem_p( //allocate permanent space 00106 inT32 count //block size to allocate 00107 ); 00108 extern DLLSYM void *alloc_mem( //get some memory 00109 inT32 count //no of bytes to get 00110 ); 00111 //get some memory 00112 extern DLLSYM void *alloc_big_mem(inT32 count //no of bytes to get 00113 ); 00114 //get some memory 00115 extern DLLSYM void *alloc_big_zeros(inT32 count //no of bytes to get 00116 ); 00117 extern DLLSYM void free_mem( //free mem from alloc_mem 00118 void *oldchunk //chunk to free 00119 ); 00120 extern DLLSYM void free_big_mem( //free mem from alloc_mem 00121 void *oldchunk //chunk to free 00122 ); 00123 #endif