00001 00030 #include <itpp/base/factory.h> 00031 00033 00034 namespace itpp { 00035 00036 template<> 00037 void create_elements(unsigned char* &ptr, int n, const Factory &) 00038 { 00039 void *p = operator new(sizeof(unsigned char) * n); 00040 ptr = reinterpret_cast<unsigned char*>(p); 00041 } 00042 00043 template<> 00044 void create_elements(bin* &ptr, int n, const Factory &) 00045 { 00046 void *p = operator new(sizeof(bin) * n); 00047 ptr = reinterpret_cast<bin*>(p); 00048 } 00049 00050 template<> 00051 void create_elements(short int* &ptr, int n, const Factory &) 00052 { 00053 void *p = operator new(sizeof(short int) * n); 00054 ptr = reinterpret_cast<short int*>(p); 00055 } 00056 00057 template<> 00058 void create_elements(int* &ptr, int n, const Factory &) 00059 { 00060 void *p = operator new(sizeof(int) * n); 00061 ptr = reinterpret_cast<int*>(p); 00062 } 00063 00064 // The following specialisation allocate memory using 16-byte alignment 00065 template<> 00066 void create_elements(double* &ptr, int n, const Factory &) 00067 { 00068 void *p0 = operator new(sizeof(double) * n + 16); 00069 void *p1 = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(p0) + 16) 00070 & (~(std::size_t(15)))); 00071 *(reinterpret_cast<void**>(p1) - 1) = p0; 00072 ptr = reinterpret_cast<double*>(p1); 00073 } 00074 00075 // The following specialisation allocate memory using 16-byte alignment 00076 template<> 00077 void create_elements(std::complex<double>* &ptr, int n, const Factory &) 00078 { 00079 void *p0 = operator new(sizeof(std::complex<double>) * n + 16); 00080 void *p1 = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(p0) + 16) 00081 & (~(std::size_t(15)))); 00082 *(reinterpret_cast<void**>(p1) - 1) = p0; 00083 ptr = reinterpret_cast<std::complex<double>*>(p1); 00084 } 00085 00086 00087 template<> 00088 void destroy_elements(unsigned char* &ptr, int n) 00089 { 00090 if (ptr) { 00091 void *p = reinterpret_cast<void*>(ptr); 00092 operator delete(p); 00093 } 00094 } 00095 00096 template<> 00097 void destroy_elements(bin* &ptr, int n) 00098 { 00099 if (ptr) { 00100 void *p = reinterpret_cast<void*>(ptr); 00101 operator delete(p); 00102 ptr = 0; 00103 } 00104 } 00105 00106 template<> 00107 void destroy_elements(short int* &ptr, int n) 00108 { 00109 if (ptr) { 00110 void *p = reinterpret_cast<void*>(ptr); 00111 operator delete(p); 00112 ptr = 0; 00113 } 00114 } 00115 00116 template<> 00117 void destroy_elements(int* &ptr, int n) 00118 { 00119 if (ptr) { 00120 void *p = reinterpret_cast<void*>(ptr); 00121 operator delete(p); 00122 ptr = 0; 00123 } 00124 } 00125 00126 00127 template<> 00128 void destroy_elements(double* &ptr, int n) 00129 { 00130 if (ptr) { 00131 void *p = *(reinterpret_cast<void**>(ptr) - 1); 00132 operator delete(p); 00133 ptr = 0; 00134 } 00135 } 00136 00137 template<> 00138 void destroy_elements(std::complex<double>* &ptr, int n) 00139 { 00140 if (ptr) { 00141 void *p = *(reinterpret_cast<void**>(ptr) - 1); 00142 operator delete(p); 00143 ptr = 0; 00144 } 00145 } 00146 00147 } 00148
Generated on Sun Dec 9 17:38:40 2007 for IT++ by Doxygen 1.5.4