Home | History | Annotate | Download | only in debase
      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 
     30 DE_BEGIN_EXTERN_C
     31 
     32 #define DE_NEW(TYPE)			((TYPE*)deMalloc(sizeof(TYPE)))
     33 #define DE_DELETE(TYPE, PTR)	deFree(PTR)
     34 
     35 void*	deMalloc		(size_t numBytes);
     36 void*	deCalloc		(size_t numBytes);
     37 void*	deRealloc		(void* ptr, size_t numBytes);
     38 void	deFree			(void* ptr);
     39 
     40 void*	deAlignedMalloc	(size_t numBytes, size_t alignBytes);
     41 void*	deAlignedRealloc(void* ptr, size_t numBytes, size_t alignBytes);
     42 void	deAlignedFree	(void* ptr);
     43 
     44 char*	deStrdup		(const char* str);
     45 
     46 /*--------------------------------------------------------------------*//*!
     47  * \brief Fill a block of memory with an 8-bit value.
     48  * \param ptr		Pointer to memory to free.
     49  * \param value		Value to fill with.
     50  * \param numBytes	Number of bytes to write.
     51  *//*--------------------------------------------------------------------*/
     52 DE_INLINE void deMemset (void* ptr, int value, size_t numBytes)
     53 {
     54 	DE_ASSERT((value & 0xFF) == value);
     55 	memset(ptr, value, numBytes);
     56 }
     57 
     58 DE_INLINE int deMemCmp (const void* a, const void* b, size_t numBytes)
     59 {
     60 	return memcmp(a, b, numBytes);
     61 }
     62 
     63 /*--------------------------------------------------------------------*//*!
     64  * \brief Copy bytes between buffers
     65  * \param dst		Destination buffer
     66  * \param src		Source buffer
     67  * \param numBytes	Number of bytes to copy
     68  * \return Destination buffer.
     69  *//*--------------------------------------------------------------------*/
     70 DE_INLINE void* deMemcpy (void* dst, const void* src, size_t numBytes)
     71 {
     72 	return memcpy(dst, src, numBytes);
     73 }
     74 
     75 DE_INLINE void* deMemmove (void* dst, const void* src, size_t numBytes)
     76 {
     77 	return memmove(dst, src, numBytes);
     78 }
     79 
     80 void	deMemory_selfTest	(void);
     81 
     82 DE_END_EXTERN_C
     83 
     84 #endif /* _DEMEMORY_H */
     85