/*   ncbimem.h
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE                          
*               National Center for Biotechnology Information
*                                                                          
*  This software/database is a "United States Government Work" under the   
*  terms of the United States Copyright Act.  It was written as part of    
*  the author's official duties as a United States Government employee and 
*  thus cannot be copyrighted.  This software/database is freely available 
*  to the public for use. The National Library of Medicine and the U.S.    
*  Government have not placed any restriction on its use or reproduction.  
*                                                                          
*  Although all reasonable efforts have been taken to ensure the accuracy  
*  and reliability of the software and data, the NLM and the U.S.          
*  Government do not and cannot warrant the performance or results that    
*  may be obtained by using this software or data. The NLM and the U.S.    
*  Government disclaim all warranties, express or implied, including       
*  warranties of performance, merchantability or fitness for any particular
*  purpose.                                                                
*                                                                          
*  Please cite the author in any work or product based on this material.   
*
* ===========================================================================
*
* File Name:  ncbimem.h
*
* Author:  Gish, Kans, Ostell, Schuler
*
* Version Creation Date:   1/1/91
*
* $Revision: 2.8 $
*
* File Description: 
*   	prototypes for ncbi memory functions
*
* Modifications:  
* --------------------------------------------------------------------------
* Date     Name        Description of modification
* -------  ----------  -----------------------------------------------------
* 9-19-91  Schuler     Modified existing prototypes for ANSI-resemblance
* 9-19-91  Schuler     Added new prototypes for Windows ANSI-like functions
* 9-19-91  Schuler     Changed all functions to _cdecl calling convention
* 04-15-93 Schuler     Changed _cdecl to LIBCALL
* 05-21-93 Schuler     Nlm_MemFreeTrace added for debugging MemFree
* 06-14-93 Schuler     Added dll_Malloc and dll_Free
*
* ==========================================================================
*/
#ifndef _NCBIMEM_
#define _NCBIMEM_

#ifdef __cplusplus
extern "C" {
#endif

/* ======== PROTOTYPES ======== */

Nlm_VoidPtr LIBCALL Nlm_MemNew PROTO((size_t size));
Nlm_VoidPtr LIBCALL Nlm_MemGet PROTO((size_t size, Nlm_Boolean clear_out));
Nlm_VoidPtr LIBCALL Nlm_MemMore PROTO((Nlm_VoidPtr ptr, size_t size));
Nlm_VoidPtr LIBCALL Nlm_MemExtend PROTO((Nlm_VoidPtr ptr, size_t size, size_t oldsize));
Nlm_VoidPtr LIBCALL Nlm_MemFree PROTO((Nlm_VoidPtr ptr));
Nlm_VoidPtr LIBCALL Nlm_MemCopy PROTO((Nlm_VoidPtr dst, Nlm_VoidPtr src, size_t bytes));
Nlm_VoidPtr LIBCALL Nlm_MemMove PROTO((Nlm_VoidPtr dst, Nlm_VoidPtr src, size_t bytes));
Nlm_VoidPtr LIBCALL Nlm_MemFill PROTO((Nlm_VoidPtr ptr, int value, size_t bytes));
Nlm_VoidPtr LIBCALL Nlm_MemDup PROTO((Nlm_VoidPtr orig, size_t size));

#if (defined(OS_MAC) || defined(WIN_MSWIN))
Nlm_Handle  LIBCALL Nlm_HandNew PROTO((size_t size));
Nlm_Handle  LIBCALL Nlm_HandGet PROTO((size_t size, Nlm_Boolean clear_out));
Nlm_Handle  LIBCALL Nlm_HandMore PROTO((Nlm_Handle hnd, size_t size));
Nlm_Handle  LIBCALL Nlm_HandFree PROTO((Nlm_Handle hnd));
Nlm_VoidPtr LIBCALL Nlm_HandLock PROTO((Nlm_Handle hnd));
Nlm_VoidPtr LIBCALL Nlm_HandUnlock PROTO((Nlm_Handle hnd));
#endif

#ifdef WIN16
Pointer LIBCALL win16_Malloc (size_t bytes);
Pointer LIBCALL win16_Calloc (size_t items, size_t size);
Pointer LIBCALL win16_Realloc (Pointer ptr, size_t size);
void    LIBCALL win16_Free (Pointer ptr);
#endif

#ifdef WIN_MAC
#ifdef USE_MAC_MEMORY
void *mac_Malloc  PROTO((size_t size));
void *mac_Calloc  PROTO((size_t nmemb, size_t size));
void *mac_Realloc PROTO((void *ptr, size_t size));
void  mac_Free    PROTO((void *ptr));
#endif
#endif

/* ========= MACROS ======== */

/* low-level ANSI-style functions */
#ifdef WIN16
#define Nlm_Malloc  win16_Malloc
#define Nlm_Calloc  win16_Calloc
#define Nlm_Realloc win16_Realloc
#define Nlm_Free    win16_Free
#define Nlm_MemSet  _fmemset
#define Nlm_MemCpy  _fmemcpy
#define Nlm_MemChr  _fmemchr
#define Nlm_MemCmp  _fmemcmp
#else
#ifdef USE_MAC_MEMORY
#define Nlm_Malloc  mac_Malloc
#define Nlm_Calloc  mac_Calloc
#define Nlm_Realloc mac_Realloc
#define Nlm_Free    mac_Free
#define Nlm_MemSet  memset
#define Nlm_MemCpy  memcpy
#define Nlm_MemChr  memchr
#define Nlm_MemCmp  memcmp
#else
#define Nlm_Malloc  malloc
#define Nlm_Calloc  calloc
#define Nlm_Realloc realloc
#define Nlm_Free    free
#define Nlm_MemSet  memset
#define Nlm_MemCpy  memcpy
#define Nlm_MemChr  memchr
#define Nlm_MemCmp  memcmp
#endif
#endif

#define Malloc  Nlm_Malloc
#define Calloc  Nlm_Calloc
#define Realloc Nlm_Realloc
#define Free    Nlm_Free
#define MemSet  Nlm_MemSet
#define MemCpy  Nlm_MemCpy
#define MemChr  Nlm_MemChr
#define MemCmp  Nlm_MemCmp

/*** High-level NCBI functions ***/

/* Fake handle functions with pointer functions */

#if !( defined(OS_MAC) || defined(WIN_MSWIN) )
#define Nlm_HandNew(a)    Nlm_MemNew(a)    
#define Nlm_HandGet(a,b)  Nlm_MemGet(a,b)
#define Nlm_HandMore(a,b) Nlm_MemMore(a,b)
#define Nlm_HandFree(a)   Nlm_MemFree(a)
#define Nlm_HandLock(a)   (a)
#define Nlm_HandUnlock(a) NULL
#endif

/* Pointer functions */
#define MemNew      Nlm_MemNew
#define MemGet      Nlm_MemGet
#define MemFree     Nlm_MemFree
#define MemMore     Nlm_MemMore
#define MemExtend   Nlm_MemExtend
#define MemCopy     Nlm_MemCopy
#define MemMove     Nlm_MemMove
#define MemFill     Nlm_MemFill
#define MemDup      Nlm_MemDup

#define HandNew     Nlm_HandNew
#define HandGet     Nlm_HandGet
#define HandMore    Nlm_HandMore
#define HandFree    Nlm_HandFree
#define HandLock    Nlm_HandLock
#define HandUnlock  Nlm_HandUnlock

Pointer LIBCALL Nlm_MemFreeTrace PROTO((Pointer ptr, const char *file, int line));

#ifdef _DEBUG
#ifndef THIS_FILE
#define THIS_FILE	__FILE__
#endif
#undef MemFree
#define MemFree(_ptr_)	Nlm_MemFreeTrace(_ptr_,THIS_FILE,__LINE__)
#endif


#ifdef _WINDLL
void * dll_Malloc (size_t bytes);
void   dll_Free (void *pMem);
#else
#define dll_Malloc(x)	(void*)Nlm_Malloc(x)
#define dll_Free(x)	Nlm_Free((void*)(x))
#endif

#ifdef __cplusplus
}
#endif

#endif
