/****************************************************************************** libx42.net - skinned vertex animation library (.NET API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #pragma once System::String^ GetGcString( const char *str ); template< typename T, size_t sizeofT = sizeof( T ), size_t alignT = __alignof( T ) > class mem_helper { public: mem_helper( void ) : ptr( 0 ) { } mem_helper( size_t numTs ) : ptr( 0 ) { ptr = (T*)_aligned_malloc( sizeofT * numTs, alignT ); if( !ptr ) throw gcnew Exception( "Failed to allocate memory buffer." ); } ~mem_helper( void ) { if( ptr ) _aligned_free( ptr ); } void alloc( size_t numTs ) { if( ptr ) _aligned_free( ptr ); ptr = (T*)_aligned_malloc( sizeofT * numTs, alignT ); if( !ptr ) throw gcnew Exception( "Failed to allocate memory buffer." ); } T* get( void ) { return ptr; } void release( void ) { ptr = 0; } template< typename Y > static void free( Y* %p ) { if( p ) { _aligned_free( p ); p = 0; } } private: T *ptr; }; typedef mem_helper< void, 1, sizeof( void* ) > buf_helper;