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