Mercurial > hg > x
annotate align8.cpp @ 13:de3961f74f30 tip
Add Linux/gcc Makefile; build fix
author | Chris Cannam |
---|---|
date | Mon, 05 Sep 2011 15:22:35 +0100 |
parents | 977f541d6683 |
children |
rev | line source |
---|---|
xue@11 | 1 /* |
xue@11 | 2 Harmonic sinusoidal modelling and tools |
xue@11 | 3 |
xue@11 | 4 C++ code package for harmonic sinusoidal modelling and relevant signal processing. |
xue@11 | 5 Centre for Digital Music, Queen Mary, University of London. |
xue@11 | 6 This file copyright 2011 Wen Xue. |
xue@11 | 7 |
xue@11 | 8 This program is free software; you can redistribute it and/or |
xue@11 | 9 modify it under the terms of the GNU General Public License as |
xue@11 | 10 published by the Free Software Foundation; either version 2 of the |
xue@11 | 11 License, or (at your option) any later version. |
xue@11 | 12 */ |
xue@1 | 13 //--------------------------------------------------------------------------- |
xue@1 | 14 |
xue@1 | 15 |
xue@1 | 16 #include <memory.h> |
xue@1 | 17 #include <stdlib.h> |
xue@1 | 18 #include "align8.h" |
xue@1 | 19 |
xue@1 | 20 //--------------------------------------------------------------------------- |
xue@1 | 21 /* |
xue@1 | 22 function malloc8: 8-byte (64-bit) aligned memory allocation. |
xue@1 | 23 |
xue@1 | 24 Returns pointer to a memory block of $size starting at an address divisible by 8. |
xue@1 | 25 */ |
xue@1 | 26 void* malloc8(unsigned size) |
xue@1 | 27 { |
Chris@4 | 28 #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) |
xue@1 | 29 char *buffer, *result; |
xue@1 | 30 buffer=(char*)malloc(size+8+sizeof(void*)); |
xue@1 | 31 if(!buffer) return(NULL); |
xue@1 | 32 char* tmp=&buffer[sizeof(void*)]; |
xue@1 | 33 result=&((char*)((unsigned)tmp&0xFFFFFFF8))[8]; |
xue@1 | 34 ((void**)result)[-1]=buffer; |
xue@1 | 35 return(result); |
Chris@4 | 36 #else |
Chris@4 | 37 return malloc(size); |
Chris@4 | 38 #endif |
xue@1 | 39 }//malloc8 |
xue@1 | 40 |
xue@1 | 41 /* |
xue@1 | 42 function free8: deallocation for malloc8() |
xue@1 | 43 |
xue@1 | 44 No return value. |
xue@1 | 45 */ |
xue@1 | 46 void free8(void* buffer8) |
xue@1 | 47 { |
Chris@4 | 48 #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) |
Chris@4 | 49 if (buffer8) free(((void**)buffer8)[-1]); |
Chris@4 | 50 #else |
Chris@4 | 51 free(buffer8); |
Chris@4 | 52 #endif |
xue@1 | 53 }//free8 |
Chris@4 | 54 |