tesseract 3.04.01

cutil/emalloc.h File Reference

#include "host.h"
#include "callcpp.h"

Go to the source code of this file.

Defines

#define NOTENOUGHMEMORY   2000
#define ILLEGALMALLOCREQUEST   2001

Functions

void * Emalloc (int Size)
void * Erealloc (void *ptr, int size)
void Efree (void *ptr)

Define Documentation

#define ILLEGALMALLOCREQUEST   2001

Definition at line 28 of file emalloc.h.

#define NOTENOUGHMEMORY   2000

---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------

Definition at line 27 of file emalloc.h.


Function Documentation

void Efree ( void *  ptr)

Definition at line 79 of file emalloc.cpp.

                      { 
  if (ptr == NULL)
    DoError (ILLEGALMALLOCREQUEST, "Attempted to free NULL ptr");

  free(ptr); 

}                                /* Efree */
void* Emalloc ( int  Size)

---------------------------------------------------------------------------- Public Function Prototypes ----------------------------------------------------------------------------

This routine attempts to allocate the specified number of bytes. If the memory can be allocated, a pointer to the memory is returned. If the memory cannot be allocated, or if the allocation request is negative or zero, an error is trapped.

Parameters:
Sizenumber of bytes of memory to be allocated
Returns:
Pointer to allocated memory.
Note:
Exceptions:
History: 4/3/89, DSJ, Created.

Definition at line 47 of file emalloc.cpp.

                        {
  void *Buffer;

  if (Size <= 0)
    DoError (ILLEGALMALLOCREQUEST, "Illegal malloc request size");
  Buffer = (void *) malloc (Size);
  if (Buffer == NULL) {
    DoError (NOTENOUGHMEMORY, "Not enough memory");
    return (NULL);
  }
  else
    return (Buffer);

}                                /* Emalloc */
void* Erealloc ( void *  ptr,
int  size 
)

Definition at line 64 of file emalloc.cpp.

                                    {
  void *Buffer;

  if (size < 0 || (size == 0 && ptr == NULL))
    DoError (ILLEGALMALLOCREQUEST, "Illegal realloc request size");

  Buffer = (void *) realloc (ptr, size);
  if (Buffer == NULL && size != 0)
    DoError (NOTENOUGHMEMORY, "Not enough memory");
  return (Buffer);

}                                /* Erealloc */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines