Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7576246
memory.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
3 KB
Referenced Files
None
Subscribers
None
memory.h
View Options
/*
* Memory functions
*
* Copyright (c) 2006-2012, Joachim Metz <jbmetz@users.sourceforge.net>
*
* Refer to AUTHORS for acknowledgements.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined( _MEMORY_H )
#define _MEMORY_H
#include "common.h"
#if defined( MEMWATCH )
#include "memwatch.h"
#endif
#if defined( HAVE_GLIB_H )
#include <glib.h>
#endif
#if defined( HAVE_STDLIB_H ) || defined( WINAPI )
#include <stdlib.h>
#endif
#if defined( HAVE_STRING_H ) || defined( WINAPI )
#include <string.h>
#endif
#if defined( __cplusplus )
extern "C" {
#endif
/* Memory allocation
*/
#if defined( HAVE_GLIB_H )
#define memory_allocate( size ) \
g_malloc( (gsize) size )
#elif defined( HAVE_MALLOC ) || ( defined( WINAPI ) && defined( USE_CRT_FUNCTIONS ) )
#define memory_allocate( size ) \
malloc( size )
#elif defined( WINAPI )
#define memory_allocate( size ) \
HeapAlloc( GetProcessHeap(), 0, (SIZE_T) size )
#endif
#define memory_allocate_structure( type ) \
(type *) memory_allocate( sizeof( type ) )
#define memory_allocate_structure_as_value( type ) \
(intptr_t *) memory_allocate( sizeof( type ) )
/* Memory reallocation
*/
#if defined( HAVE_GLIB_H )
#define memory_reallocate( buffer, size ) \
g_realloc( (gpointer) buffer, (gsize) size )
#elif defined( HAVE_REALLOC ) || ( defined( WINAPI ) && defined( USE_CRT_FUNCTIONS ) )
#define memory_reallocate( buffer, size ) \
realloc( (void *) buffer, size )
#elif defined( WINAPI )
/* HeapReAlloc does not allocate empty (NULL) buffers as realloc does
*/
#define memory_reallocate( buffer, size ) \
( buffer == NULL ) ? \
HeapAlloc( GetProcessHeap(), 0, (SIZE_T) size ) : \
HeapReAlloc( GetProcessHeap(), 0, (LPVOID) buffer, (SIZE_T) size )
#endif
/* Memory free
*/
#if defined( HAVE_GLIB_H )
#define memory_free( buffer ) \
g_free( (gpointer) buffer )
#elif defined( HAVE_FREE ) || ( defined( WINAPI ) && defined( USE_CRT_FUNCTIONS ) )
#define memory_free( buffer ) \
free( (void *) buffer )
#elif defined( WINAPI )
#define memory_free( buffer ) \
HeapFree( GetProcessHeap(), 0, (LPVOID) buffer )
#endif
/* Memory compare
*/
#if defined( HAVE_MEMCMP ) || defined( WINAPI )
#define memory_compare( buffer1, buffer2, size ) \
memcmp( (const void *) buffer1, (const void *) buffer2, size )
#endif
/* Memory copy
*/
#if defined( HAVE_MEMCPY ) || defined( WINAPI )
#define memory_copy( destination, source, count ) \
memcpy( (void *) destination, (void *) source, count )
#endif
/* Memory set
*/
#if defined( HAVE_MEMSET ) || defined( WINAPI )
#define memory_set( buffer, value, count ) \
memset( (void *) buffer, (int) value, count )
#endif
#if defined( __cplusplus )
}
#endif
#endif
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Oct 10, 11:32 PM (23 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1339922
Default Alt Text
memory.h (3 KB)
Attached To
Mode
rXMOUNT xmount
Attached
Detach File
Event Timeline
Log In to Comment