nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "NuxCore.h" 00024 00025 namespace nux 00026 { 00027 00028 t_u32 Memcmp ( const void *Buf1, const void *Buf2, t_u32 Count ) 00029 { 00030 return std::memcmp ( Buf1, Buf2, Count ); 00031 } 00032 00033 bool MemIsZero ( const void *V, t_size Count ) 00034 { 00035 t_u8 *B = (t_u8 *) V; 00036 00037 while ( Count-- > 0 ) 00038 if ( *B++ != 0 ) 00039 return false; 00040 00041 return true; 00042 } 00043 00044 void *Memmove ( void *Dest, const void *Src, t_size Count ) 00045 { 00046 if (Count == 0) 00047 return Dest; 00048 00049 return std::memmove ( Dest, Src, Count ); 00050 } 00051 00052 void Memset ( void *Dest, t_s32 C, t_size Count ) 00053 { 00054 std::memset ( Dest, C, Count ); 00055 } 00056 00057 void Memzero ( void *Dest, t_size Count ) 00058 { 00059 std::memset ( Dest, 0, Count ); 00060 } 00061 00062 void Memcpy ( void *Dest, const void *Src, t_size Count ) 00063 { 00064 std::memcpy ( Dest, Src, Count ); 00065 } 00066 00067 void Memswap ( void *Ptr1, void *Ptr2, t_size Size ) 00068 { 00069 void *Temp = malloc (Size); 00070 Memcpy ( Temp, Ptr1, Size ); 00071 Memcpy ( Ptr1, Ptr2, Size ); 00072 Memcpy ( Ptr2, Temp, Size ); 00073 free (Temp); 00074 } 00075 00076 bool IsMemoryAligned (void *data, t_u32 alignment) 00077 { 00078 nuxAssertMsg ( (alignment & (alignment - 1) ) == 0, TEXT ("[IsMemAligned] Argument for memory alignment test is not a power of two: %d"), alignment); 00079 return ( ( (uintptr_t) &data) & (alignment - 1) ) == 0; 00080 } 00081 00082 void *Malloc (t_size Count, t_u32 Alignment) 00083 { 00084 return std::malloc ( Count ); 00085 } 00086 00087 void *Realloc (void *Original, t_size Count, t_u32 Alignment) 00088 { 00089 void *mem = std::realloc ( Original, Count ); 00090 00091 if (mem == 0) 00092 { 00093 nuxCriticalMsg (TEXT ("[Realloc] realloc failed.")); 00094 return NULL; 00095 } 00096 00097 return mem; 00098 } 00099 00100 }