/*!ignore \file NMemory.h \brief Provides memory management for Neurotechnology components. */

/*!ignore
|******************************************************************************|
|*                                                                            *|
|*                           Neurotechnology Core 2.4                         *|
|*                                                                            *|
|* NMemory.h                                                                  *|
|* Header file for NMemory module                                             *|
|*                                                                            *|
|* Copyright (C) 2005-2008 Neurotechnology                                    *|
|*                                                                            *|
\******************************************************************************/

#ifndef N_MEMORY_H_INCLUDED
#define N_MEMORY_H_INCLUDED

#include "NTypes.h"

#ifdef N_CPP
extern "C"
{
#endif

/*!ignore
 * \brief  Allocates memory block.
 */
NResult N_API NAlloc(NSizeType size, void * * ppBlock);
/*!ignore
 * \brief  Allocates memory block with all bytes set to zero.
 */
NResult N_API NCAlloc(NSizeType size, void * * ppBlock);
/*!ignore
 * \brief  Reallocates memory block.
 */
NResult N_API NReAlloc(void * * ppBlock, NSizeType size);
/*!ignore
 * \brief  Deallocates memory block.
 */
void N_API NFree(void * pBlock);

/*!ignore
 * \brief  Copies data between memory blocks.
 */
NResult N_API NCopy(void * pDstBlock, const void * pSrcBlock, NSizeType size);
/*!ignore
 * \brief  Move data from one memory block to another.
 */
NResult N_API NMove(void * pDstBlock, const void * pSrcBlock, NSizeType size);
/*!ignore
 * \brief  Sets bytes of memory block to specified value.
 */
NResult N_API NFill(void * pBlock, NByte value, NSizeType size);
/*!ignore
 * \brief  Clears memory block.
 */
#define NClear(pBlock, count) NFill(pBlock, 0, count)
/*!ignore
 * \brief  Compares bytes in two memory blocks.
 */
NResult N_API NCompare(const void * pBlock1, const void * pBlock2, NSizeType size, NInt * pResult);

NResult N_API NAlignedOffsetAlloc(NSizeType size, NSizeType alignment, NSizeType offset, void **ppBlock);
NResult N_API NAlignedOffsetCAlloc(NSizeType size, NSizeType alignment, NSizeType offset, void **ppBlock);
NResult N_API NAlignedOffsetReAlloc(NSizeType size, NSizeType alignment, NSizeType offset, void **ppBlock);
void N_API NAlignedFree(void *pBlock);
#define NAlignedAlloc(size, alignment, ppBlock) NAlignedOffsetAlloc(size, alignment, 0, ppBlock)
#define NAlignedCAlloc(size, alignment, ppBlock) NAlignedOffsetCAlloc(size, alignment, 0, ppBlock)
#define NAlignedReAlloc(size, alignment, ppBlock) NAlignedOffsetReAlloc(size, alignment, 0, ppBlock)

#ifdef N_CPP
}
#endif

#endif /*!ignore !N_MEMORY_H_INCLUDED */
