Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
memry.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: memry.c (Formerly memory.c)
3  * Description: Memory allocation with builtin safety checks.
4  * Author: Ray Smith
5  * Created: Wed Jan 22 09:43:33 GMT 1992
6  *
7  * (C) Copyright 1992, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "mfcpch.h"
21 #include "memry.h"
22 #include <stdlib.h>
23 
24 // With improvements in OS memory allocators, internal memory management
25 // is no longer required, so all these functions now map to their malloc
26 // family equivalents.
27 
28 // TODO(rays) further cleanup by redirecting calls to new and creating proper
29 // constructors.
30 
32  // Round up the amount allocated to a multiple of 4
33  return static_cast<char*>(malloc((count + 3) & ~3));
34 }
35 
36 void free_string(char *string) {
37  free(string);
38 }
39 
40 void* alloc_struct(inT32 count, const char *) {
41  return malloc(count);
42 }
43 
44 void free_struct(void *deadstruct, inT32, const char *) {
45  free(deadstruct);
46 }
47 
49  return malloc(static_cast<size_t>(count));
50 }
51 
53  return calloc(static_cast<size_t>(count), 1);
54 }
55 
56 void free_mem(void *oldchunk) {
57  free(oldchunk);
58 }
59 
60 void free_big_mem(void *oldchunk) {
61  free(oldchunk);
62 }