Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*******************************************************************
  2.  *
  3.  *  ttmemory.h                                               1.2
  4.  *
  5.  *    Memory management component (specification).
  6.  *
  7.  *  Copyright 1996-1999 by
  8.  *  David Turner, Robert Wilhelm, and Werner Lemberg.
  9.  *
  10.  *  This file is part of the FreeType project, and may only be used
  11.  *  modified and distributed under the terms of the FreeType project
  12.  *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13.  *  this file you indicate that you have read the license and
  14.  *  understand and accept it fully.
  15.  *
  16.  *  Changes between 1.2 and 1.1:
  17.  *
  18.  *  - the font pool is gone!  All allocations are now performed
  19.  *    with malloc() and free().
  20.  *
  21.  *  - introduced the FREE() macro and the Free() function for
  22.  *    future use in destructors.
  23.  *
  24.  *  - Init_FontPool() is now a macro to allow the compilation of
  25.  *    'legacy' applications (all four test programs have been updated).
  26.  *
  27.  ******************************************************************/
  28.  
  29. #ifndef TTMEMORY_H
  30. #define TTMEMORY_H
  31.  
  32. #include "ttconfig.h"
  33. #include "tttypes.h"
  34. #include <string.h>
  35.  
  36.  
  37. #ifdef __cplusplus
  38.   extern "C" {
  39. #endif
  40.  
  41. #define MEM_Set( dest, byte, count )  memset( dest, byte, count )
  42.  
  43. #ifdef HAVE_MEMCPY
  44. #define MEM_Copy( dest, source, count )  memcpy( dest, source, count )
  45. #else
  46. #define MEM_Copy( dest, source, count )  bcopy( source, dest, count )
  47. #endif
  48.  
  49. #ifdef HAVE_MEMMOVE
  50. #define MEM_Move( dest, source, count )  memmove( dest, source, count )
  51. #else
  52. #define MEM_Move( dest, source, count )  bcopy( source, dest, count )
  53. #endif
  54.  
  55.  
  56. #define MEM_Alloc( _pointer_, _size_ ) \
  57.   TT_Alloc( _size_, (void**)&(_pointer_) )
  58.  
  59. #define MEM_Realloc( _pointer_, _size_ ) \
  60.   TT_Realloc( _size_, (void**)&(_pointer_) )
  61.  
  62. #define ALLOC( _pointer_, _size_ ) \
  63.   ( ( error = MEM_Alloc( _pointer_, _size_ ) ) != TT_Err_Ok )
  64.  
  65. #define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
  66.   ( ( error = MEM_Alloc( _pointer_, \
  67.                          (_count_) * sizeof ( _type_ ) ) ) != TT_Err_Ok )
  68.  
  69. #define REALLOC( _pointer_, _size_ ) \
  70.   ( ( error = MEM_Realloc( _pointer_, _size_ ) ) != TT_Err_Ok )
  71.  
  72. #define REALLOC_ARRAY( _pointer_, _count_, _type_ ) \
  73.   ( (error = MEM_Realloc( _pointer_, \
  74.                           (_count_) * sizeof ( _type_ ) ) ) != TT_Err_Ok )
  75.  
  76. #define FREE( _pointer_ ) \
  77.   TT_Free( (void**)&(_pointer_) )
  78.  
  79.  
  80.   /* Allocate a block of memory of 'Size' bytes from the heap, and */
  81.   /* sets the pointer '*P' to its address.  If 'Size' is 0, or in  */
  82.   /* case of error, the pointer is always set to NULL.             */
  83.  
  84.   EXPORT_DEF
  85.   TT_Error  TT_Alloc( ULong  Size, void**  P );
  86.  
  87. #ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
  88.  
  89.   /* Reallocates a block of memory pointed to by '*P' to 'Size'    */
  90.   /* bytes from the heap, possibly changing '*P'.  If 'Size' is 0, */
  91.   /* TT_Free() is called, if '*P' is NULL, TT_Alloc() is called.   */
  92.   /* '*P' is freed (if it's non-NULL) in case of error.            */
  93.  
  94.   EXPORT_DEF
  95.   TT_Error  TT_Realloc( ULong  Size, void**  P );
  96.  
  97. #endif /* TT_CONFIG_OPTION_EXTEND_ENGINE */
  98.  
  99.   /* Releases a block that was previously allocated through Alloc. */
  100.   /* Note that the function returns successfully when P or *P are  */
  101.   /* already NULL.  The pointer '*P' is set to NULL on exit in     */
  102.   /* case of success.                                              */
  103.  
  104.   EXPORT_DEF
  105.   TT_Error  TT_Free( void**  P );
  106.  
  107.  
  108.   /* For "legacy" applications, that should be re-coded.              */
  109.   /* Note that this won't release the previously allocated font pool. */
  110.  
  111. #define Init_FontPool( x, y )  while( 0 ) { }
  112.  
  113.  
  114.   LOCAL_DEF TT_Error  TTMemory_Init( void );
  115.   LOCAL_DEF TT_Error  TTMemory_Done( void );
  116.  
  117.  
  118. #ifdef __cplusplus
  119.   }
  120. #endif
  121.  
  122. #endif /* TTMEMORY_H */
  123.  
  124.  
  125. /* END */
  126.