deMemory.h revision 3c827367444ee418f129b2c238299f49d3264554
1#ifndef _DEMEMORY_H 2#define _DEMEMORY_H 3/*------------------------------------------------------------------------- 4 * drawElements Base Portability Library 5 * ------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Memory management. 24 *//*--------------------------------------------------------------------*/ 25 26#include "deDefs.h" 27 28#include <string.h> 29 30DE_BEGIN_EXTERN_C 31 32#define DE_NEW(TYPE) ((TYPE*)deMalloc(sizeof(TYPE))) 33#define DE_DELETE(TYPE, PTR) deFree(PTR) 34 35void* deMalloc (int numBytes); 36void* deCalloc (int numBytes); 37void* deRealloc (void* ptr, int numBytes); 38void deFree (void* ptr); 39 40void* deAlignedMalloc (int numBytes, int alignBytes); 41void deAlignedFree (void* ptr); 42 43char* deStrdup (const char* str); 44 45/*--------------------------------------------------------------------*//*! 46 * \brief Fill a block of memory with an 8-bit value. 47 * \param ptr Pointer to memory to free. 48 * \param value Value to fill with. 49 * \param numBytes Number of bytes to write. 50 *//*--------------------------------------------------------------------*/ 51DE_INLINE void deMemset (void* ptr, int value, int numBytes) 52{ 53 DE_ASSERT((value & 0xFF) == value); 54 memset(ptr, value, numBytes); 55} 56 57DE_INLINE int deMemCmp (const void* a, const void* b, int numBytes) 58{ 59 return memcmp(a, b, numBytes); 60} 61 62/*--------------------------------------------------------------------*//*! 63 * \brief Copy bytes between buffers 64 * \param dst Destination buffer 65 * \param src Source buffer 66 * \param numBytes Number of bytes to copy 67 * \return Destination buffer. 68 *//*--------------------------------------------------------------------*/ 69DE_INLINE void* deMemcpy (void* dst, const void* src, int numBytes) 70{ 71 return memcpy(dst, src, numBytes); 72} 73 74DE_INLINE void* deMemmove (void* dst, const void* src, int numBytes) 75{ 76 return memmove(dst, src, numBytes); 77} 78 79DE_END_EXTERN_C 80 81#endif /* _DEMEMORY_H */ 82