Tesseract  3.02
tesseract-ocr/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          "mfcpch.h"
00021 #include          "memry.h"
00022 #include          <stdlib.h>
00023 
00024 // With improvements in OS memory allocators, internal memory management
00025 // is no longer required, so all these functions now map to their malloc
00026 // family equivalents.
00027 
00028 // TODO(rays) further cleanup by redirecting calls to new and creating proper
00029 // constructors.
00030 
00031 char *alloc_string(inT32 count) {
00032   // Round up the amount allocated to a multiple of 4
00033   return static_cast<char*>(malloc((count + 3) & ~3));
00034 }
00035 
00036 void free_string(char *string) {
00037   free(string);
00038 }
00039 
00040 void* alloc_struct(inT32 count, const char *) {
00041   return malloc(count);
00042 }
00043 
00044 void free_struct(void *deadstruct, inT32, const char *) {
00045   free(deadstruct);
00046 }
00047 
00048 void *alloc_mem(inT32 count) {
00049   return malloc(static_cast<size_t>(count));
00050 }
00051 
00052 void *alloc_big_zeros(inT32 count) {
00053   return calloc(static_cast<size_t>(count), 1);
00054 }
00055 
00056 void free_mem(void *oldchunk) {
00057   free(oldchunk);
00058 }
00059 
00060 void free_big_mem(void *oldchunk) {
00061   free(oldchunk);
00062 }