13 #ifndef _INCLUDE_CLIZFUNCTIONS
14 #define _INCLUDE_CLIZFUNCTIONS
20 #define CHKHEAP() (check_heap(__FILE__, __LINE__))
25 #define FLOATIFPRECISION 0.000001f
27 #define BIGFLOATVALUE 4294967269.0f
28 #define BIGINTVALUE 4294967269
30 #define ELEM_SWAP(a,b) { register float t=(a);(a)=(b);(b)=t; }
31 #define ELEM_SWAPUI(a,b) { unsigned int t=(a);(a)=(b);(b)=t; }
33 #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp;
34 #define SWAPUI(a,b) temp2=(a);(a)=(b);(b)=temp2;
35 #define SWAPFFT(a,b) tempr = (a); (a) = (b); (b) = tempr
38 #define SQR(x) ((x)*(x))
43 typedef boost::condition_variable
ConVar;
44 typedef boost::mutex::scoped_lock
Lock;
45 typedef boost::unique_lock< boost::shared_mutex >
Writelock;
46 typedef boost::shared_lock< boost::shared_mutex >
Readlock;
54 #include <boost\thread.hpp>
74 const memUInt MEMSIZE[22] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152 };
75 const memUInt POOLCAPACITY[22] = { 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 128, 128, 64, 64, 32, 16, 8, 4, 2 };
112 capacity = iCapacity;
115 startAddress = malloc(size*capacity);
116 while (!startAddress)
118 startAddress = malloc(size*capacity);
121 bitArray = (
memBool*)calloc(capacity, 1);
124 bitArray = (
memBool*)calloc(capacity, 1);
129 for (
int i = nextFreePos+1; i <
capacity; i++)
160 if (bitArray[nextFreePos])
177 bitArray[freePos] = 0;
178 nextFreePos = freePos;
200 poolCapacity = iPoolCapacity;
204 new(&pool[0])
MemPool(size, poolCapacity);
208 if (pool[poolInUse].numFree > 0)
215 for (
int i = poolInUse+1; i <
numPools; i++)
217 if (pool[i].numFree > 0)
227 if (pool[i].numFree > 0)
247 pool[freePool].
free(memAdr);
254 poolInUse = numPools++;
294 for (
int i = 0; i < memSizes; i++)
320 std::cout <<
"malloc" << std::endl;
325 memAdr = malloc(numBytes + 4 *
METASIZE);
337 sizedPools[freeSizePool].
free(memAdr);
375 for (
int i = 0; i < memSizes; i++)
400 std::cout <<
"malloc" << std::endl;
405 memAdr = malloc(numBytes + 4 *
METASIZE);
417 sizedPools[freeSizePool].
free(memAdr);
450 while (!memManMutex.try_lock());
453 if (memMan[i].isFree == 1)
459 else if (i == NUMMEMMAN - 1)
472 memManMutex.unlock();
475 memMan[memManInUse].
isFree = 1;
486 while (!memManMutex.try_lock());
487 memMan[freeMemMan].
free(memAdr);
489 memManMutex.unlock();
516 int clMax(
int a,
int b);
522 void clSort(
float vec[],
int n);
528 void clSort(
unsigned int vec[],
int n);
536 void clSortTwo(
unsigned int vec[],
unsigned int vec2[],
int n);
544 void clSortTwo(
float vec[],
float vec2[],
int n);
552 void clSortTwo(
float vec[],
unsigned int vec2[],
int n);
566 float clMedian(
unsigned int vec[],
int n);
572 float clMean(
float arr[], uint32_t n);
578 double clMean(
double arr[], uint32_t n);
584 float clStd(
float arr[], uint32_t n);
591 inline float clStdWithMean(
float arr[], uint32_t n,
float mean);
597 float *
clAbs(
float arr[], uint32_t n);
604 uint32_t
clMaxIndex(
float arr[], uint32_t begin, uint32_t end);
611 uint32_t
clMaxAbsIndex(
float arr[], uint32_t begin, uint32_t end);
618 uint32_t
clMinIndex(
float arr[], uint32_t begin, uint32_t end);
623 inline float clErfc(
float x);
690 void clXCorr(
float *X,
float *Y,
unsigned int n,
int maxshift,
float *&output,
MemoryManager &memMan);
699 void clXCorr(
double *X,
double *Y,
unsigned int n,
int maxshift,
double *&output,
MemoryManager &memMan);
void free(memPtr *memAdr)
Definition: clizFunctions.h:173
Definition: clizFunctions.h:429
memPtr * allocate(size_t numBytes)
Definition: clizFunctions.h:388
void clHaarWaveDecWithOffset(float spikes[], unsigned int size, uint8_t scales, float output[], uint32_t offset, MemoryManager &memMan)
Definition: clizFunctions.cpp:1195
const memShort METASIZE
Definition: clizFunctions.h:76
memInt poolInUse
Definition: clizFunctions.h:196
void spawnNewPool()
Definition: clizFunctions.h:249
memPtr * allocate()
Definition: clizFunctions.h:206
SizedMemPool * sizedPools
Definition: clizFunctions.h:272
const memUInt POOLCAPACITY[22]
Definition: clizFunctions.h:75
void clSplineGetY2(float y[], int n, float y2[], MemoryManager &memMan)
Definition: clizFunctions.cpp:1142
unsigned char memByte
Definition: clizFunctions.h:68
MemoryManager()
Definition: clizFunctions.h:273
memBool isFree
Definition: clizFunctions.h:271
memInt numFree
Definition: clizFunctions.h:105
~MemPool()
Definition: clizFunctions.h:182
void free(memPtr *memAdr)
Definition: clizFunctions.h:243
uint32_t clMaxAbsIndex(float arr[], uint32_t begin, uint32_t end)
Definition: clizFunctions.cpp:894
float clStd(float arr[], uint32_t n)
Definition: clizFunctions.cpp:827
void clXCorr(float *X, float *Y, unsigned int n, int maxshift, float *&output, MemoryManager &memMan)
Definition: clizFunctions.cpp:1241
memInt poolCapacity
Definition: clizFunctions.h:195
boost::unique_lock< boost::shared_mutex > writelocktype
Definition: clizFunctions.h:58
~SizedMemPool()
Definition: clizFunctions.h:258
double memDouble
Definition: clizFunctions.h:64
float memFloat
Definition: clizFunctions.h:63
unsigned int memUInt
Definition: clizFunctions.h:62
boost::thread Thread
Definition: clizFunctions.h:41
memInt numPools
Definition: clizFunctions.h:194
Definition: clizFunctions.h:99
bool memBool
Definition: clizFunctions.h:66
~MemoryManagerPart()
Definition: clizFunctions.h:380
int clBinomial(int n, int k)
Definition: clizFunctions.cpp:42
uint32_t clMinIndex(float arr[], uint32_t begin, uint32_t end)
Definition: clizFunctions.cpp:914
void clSortTwo(unsigned int vec[], unsigned int vec2[], int n)
Definition: clizFunctions.cpp:298
boost::shared_lock< boost::shared_mutex > Readlock
Definition: clizFunctions.h:46
void free(memPtr *memAdr)
Definition: clizFunctions.h:411
memInt size
Definition: clizFunctions.h:102
const memShort MEMSIZECOUNT
Definition: clizFunctions.h:73
SizedMemPool(memInt iSize, memInt iPoolCapacity)
Definition: clizFunctions.h:197
Definition: clizFunctions.h:268
void free(memPtr *memAdr)
Definition: clizFunctions.h:480
MemoryManagerPart * memMan
Definition: clizFunctions.h:433
GlobalMemoryManager()
Definition: clizFunctions.h:434
SizedMemPool * sizedPools
Definition: clizFunctions.h:353
memPtr * allocate(size_t numBytes)
Definition: clizFunctions.h:307
unsigned short memShort
Definition: clizFunctions.h:67
MemPool * pool
Definition: clizFunctions.h:192
int memInt
Definition: clizFunctions.h:61
boost::unique_lock< boost::shared_mutex > Writelock
Definition: clizFunctions.h:45
unsigned short memAdrType
Definition: clizFunctions.h:69
boost::mutex::scoped_lock Lock
Definition: clizFunctions.h:44
void clFindHighestIndices(float arr[], uint32_t n, uint32_t output[], uint32_t numindices, MemoryManager &memMan)
Definition: clizFunctions.cpp:1070
void free(memPtr *memAdr)
Definition: clizFunctions.h:331
memBool isFree
Definition: clizFunctions.h:352
int clMax(int a, int b)
Definition: clizFunctions.cpp:78
memPtr * allocate(size_t numBytes)
Definition: clizFunctions.h:447
void check_heap(char *file, int line)
Definition: clizFunctions.cpp:16
float clMedian(float vec[], int n)
Definition: clizFunctions.cpp:642
memPtr * startAddress
Definition: clizFunctions.h:103
float * clAbs(float arr[], uint32_t n)
Definition: clizFunctions.cpp:857
uint32_t clMaxIndex(float arr[], uint32_t begin, uint32_t end)
Definition: clizFunctions.cpp:874
const memUInt MEMSIZE[22]
Definition: clizFunctions.h:74
boost::mutex::scoped_lock locktype
Definition: clizFunctions.h:57
float clSplineInterp(float y[], float y2[], float x)
Definition: clizFunctions.cpp:1175
float clKSTest(float arr[], uint32_t n, MemoryManager &memMan)
Definition: clizFunctions.cpp:999
MemoryManagerPart(int memSizes)
Definition: clizFunctions.h:367
Definition: clizFunctions.h:189
void clFindLowestIndices(float arr[], uint32_t n, uint32_t output[], uint32_t numindices, MemoryManager &memMan)
Definition: clizFunctions.cpp:1104
memInt nextFreePos
Definition: clizFunctions.h:107
memBool * bitArray
Definition: clizFunctions.h:106
GlobalMemoryManager gMemMan
Definition: clizFunctions.cpp:14
float clStdWithMean(float arr[], uint32_t n, float mean)
Definition: clizFunctions.cpp:843
boost::shared_lock< boost::shared_mutex > readlocktype
Definition: clizFunctions.h:59
memInt capacity
Definition: clizFunctions.h:104
boost::mutex Mutex
Definition: clizFunctions.h:42
void clSort(float vec[], int n)
Definition: clizFunctions.cpp:92
memInt size
Definition: clizFunctions.h:193
const memShort MAXPOOLS
Definition: clizFunctions.h:71
~MemoryManager()
Definition: clizFunctions.h:299
MemoryManagerPart()
Definition: clizFunctions.h:354
const memShort NUMMEMMAN
Definition: clizFunctions.h:72
float clMean(float arr[], uint32_t n)
Definition: clizFunctions.cpp:799
float clSign(float x)
Definition: clizFunctions.cpp:61
boost::condition_variable ConVar
Definition: clizFunctions.h:43
boost::mutex memManMutex
Definition: clizFunctions.h:432
MemPool(memInt iSize, memInt iCapacity)
Definition: clizFunctions.h:109
void memPtr
Definition: clizFunctions.h:65
Definition: clizFunctions.h:349
memPtr * allocate()
Definition: clizFunctions.h:127
MemoryManager(int memSizes)
Definition: clizFunctions.h:286