tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/ccutil/memry.cpp
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        memry.c  (Formerly memory.c)
00003  * Description: Memory allocation with builtin safety checks.
00004  * Author:                                      Ray Smith
00005  * Created:                                     Wed Jan 22 09:43:33 GMT 1992
00006  *
00007  * (C) Copyright 1992, 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 #include          "memry.h"
00021 #include          <stdlib.h>
00022 
00023 // With improvements in OS memory allocators, internal memory management
00024 // is no longer required, so all these functions now map to their malloc
00025 // family equivalents.
00026 
00027 // TODO(rays) further cleanup by redirecting calls to new and creating proper
00028 // constructors.
00029 
00030 char *alloc_string(inT32 count) {
00031   // Round up the amount allocated to a multiple of 4
00032   return static_cast<char*>(malloc((count + 3) & ~3));
00033 }
00034 
00035 void free_string(char *string) {
00036   free(string);
00037 }
00038 
00039 void* alloc_struct(inT32 count, const char *) {
00040   return malloc(count);
00041 }
00042 
00043 void free_struct(void *deadstruct, inT32, const char *) {
00044   free(deadstruct);
00045 }
00046 
00047 void *alloc_mem(inT32 count) {
00048   return malloc(static_cast<size_t>(count));
00049 }
00050 
00051 void *alloc_big_zeros(inT32 count) {
00052   return calloc(static_cast<size_t>(count), 1);
00053 }
00054 
00055 void free_mem(void *oldchunk) {
00056   free(oldchunk);
00057 }
00058 
00059 void free_big_mem(void *oldchunk) {
00060   free(oldchunk);
00061 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines