From e638bb8ae1f78e6bb06e2150c8ec288c0bfbf35e Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 26 Apr 2014 18:10:36 +0300 Subject: [PATCH] MemoryHelper: update coding style --- include/MemoryHelper.h | 10 +++++----- src/core/MemoryHelper.cpp | 41 ++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/MemoryHelper.h b/include/MemoryHelper.h index 624f326ec..f646c7ef3 100644 --- a/include/MemoryHelper.h +++ b/include/MemoryHelper.h @@ -22,18 +22,18 @@ */ -#ifndef _MEMORY_HELPER_H_ -#define _MEMORY_HELPER_H_ +#ifndef MEMORY_HELPER_H +#define MEMORY_HELPER_H /** * Helper class to alocate aligned memory and free it. */ class MemoryHelper { public: - - static void* alignedMalloc(int); - static void alignedFree(void*); + static void* alignedMalloc( int ); + + static void alignedFree( void* ); private: }; diff --git a/src/core/MemoryHelper.cpp b/src/core/MemoryHelper.cpp index 28a97abe4..3513ee763 100644 --- a/src/core/MemoryHelper.cpp +++ b/src/core/MemoryHelper.cpp @@ -27,42 +27,39 @@ #include "MemoryHelper.h" /** - * Allocate a number of bytes and return them. - * @param _byteNum is the number of bytes + * Allocate a number of bytes and return them. + * @param byteNum is the number of bytes */ -void* MemoryHelper::alignedMalloc(int _byteNum) { - char *ptr,*ptr2,*aligned_ptr; - int align_mask = ALIGN_SIZE- 1; +void* MemoryHelper::alignedMalloc( int byteNum ) +{ + char *ptr, *ptr2, *aligned_ptr; + int align_mask = ALIGN_SIZE - 1; - ptr = (char *) malloc(_byteNum + ALIGN_SIZE + sizeof(int)); + ptr = static_cast( malloc( byteNum + ALIGN_SIZE + sizeof( int ) ) ); - if(ptr==NULL) return(NULL); + if( ptr == NULL ) return NULL; - ptr2 = ptr + sizeof(int); - aligned_ptr = ptr2 + (ALIGN_SIZE- ((size_t)ptr2 & align_mask)); + ptr2 = ptr + sizeof( int ); + aligned_ptr = ptr2 + ( ALIGN_SIZE - ( ( size_t ) ptr2 & align_mask ) ); - ptr2 = aligned_ptr - sizeof(int); - *((int *)ptr2)=(int)(aligned_ptr - ptr); + ptr2 = aligned_ptr - sizeof( int ); + *( ( int* ) ptr2 ) = ( int )( aligned_ptr - ptr ); - return(aligned_ptr); + return aligned_ptr; } - - /** * Free an aligned buffer * @param _buffer is the buffer to free */ -void MemoryHelper::alignedFree(void* _buffer) { - if( _buffer != NULL ) +void MemoryHelper::alignedFree( void* _buffer ) +{ + if( _buffer ) { - int *ptr2=(int *)_buffer - 1; - _buffer = (char *)_buffer - *ptr2; - free(_buffer); + int *ptr2 = static_cast( _buffer ) - 1; + _buffer = static_cast( _buffer ) - *ptr2; + free( _buffer ); } } - - -