From 11b37fe1de1c659725cd4a3982ab8f275431e950 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Tue, 4 Nov 2014 14:54:03 -0800 Subject: [PATCH] maybe breaking things here --- .../library/platform/utils/Base/Statistics.h | 2 +- .../utils/Base/win32/BlockAllocator.cpp | 4 +- .../CSAssist/utils/Base/BlockAllocator.h | 2 +- .../CSAssist/utils/Base/Statistics.h | 2 +- .../utils/Base/win32/BlockAllocator.cpp | 172 +++++++++--------- .../ChatAPI/utils/Base/BlockAllocator.h | 2 +- .../utils/Base/win32/BlockAllocator.cpp | 172 +++++++++--------- 7 files changed, 178 insertions(+), 178 deletions(-) diff --git a/external/3rd/library/platform/utils/Base/Statistics.h b/external/3rd/library/platform/utils/Base/Statistics.h index 18e0579e..b39f755f 100644 --- a/external/3rd/library/platform/utils/Base/Statistics.h +++ b/external/3rd/library/platform/utils/Base/Statistics.h @@ -36,7 +36,7 @@ namespace Base if (!mLastSampleTime) mLastSampleTime = time(NULL); - if (!mSampleFrequency || mLastSampleTime + mSampleFrequency < (unsigned)time(NULL)) + if (!mSampleFrequency || mLastSampleTime + mSampleFrequency < (uintptr_t)time(NULL)) { mSampleTotal++; mAggregateTotal += value; diff --git a/external/3rd/library/platform/utils/Base/win32/BlockAllocator.cpp b/external/3rd/library/platform/utils/Base/win32/BlockAllocator.cpp index 029946b4..2ed57637 100644 --- a/external/3rd/library/platform/utils/Base/win32/BlockAllocator.cpp +++ b/external/3rd/library/platform/utils/Base/win32/BlockAllocator.cpp @@ -79,7 +79,7 @@ namespace Base if(m_blocks[accum] == 0) { // remove the pre allocated block from the linked list - handle = (uintptr_t *)calloc(((1 << accum) / 4) + 2, sizeof(unsigned)); + handle = (uintptr_t *)calloc(((1 << accum) / 4) + 2, sizeof(uintptr_t)); handle[1] = accum; handle[0] = 0; } @@ -94,7 +94,7 @@ namespace Base return(handle + 2); } - void BlockAllocator::returnBlock(unsigned *handle) + void BlockAllocator::returnBlock(uintptr_t *handle) { // C++ allows for safe deletion of a NULL pointer if(handle) diff --git a/external/3rd/library/soePlatform/CSAssist/utils/Base/BlockAllocator.h b/external/3rd/library/soePlatform/CSAssist/utils/Base/BlockAllocator.h index 5daf69da..bbfbf273 100644 --- a/external/3rd/library/soePlatform/CSAssist/utils/Base/BlockAllocator.h +++ b/external/3rd/library/soePlatform/CSAssist/utils/Base/BlockAllocator.h @@ -20,7 +20,7 @@ namespace Base void returnBlock(unsigned *handle); private: - unsigned *m_blocks[31]; + uintptr_t *m_blocks[31]; }; }; #ifdef EXTERNAL_DISTRO diff --git a/external/3rd/library/soePlatform/CSAssist/utils/Base/Statistics.h b/external/3rd/library/soePlatform/CSAssist/utils/Base/Statistics.h index 18e0579e..b39f755f 100644 --- a/external/3rd/library/soePlatform/CSAssist/utils/Base/Statistics.h +++ b/external/3rd/library/soePlatform/CSAssist/utils/Base/Statistics.h @@ -36,7 +36,7 @@ namespace Base if (!mLastSampleTime) mLastSampleTime = time(NULL); - if (!mSampleFrequency || mLastSampleTime + mSampleFrequency < (unsigned)time(NULL)) + if (!mSampleFrequency || mLastSampleTime + mSampleFrequency < (uintptr_t)time(NULL)) { mSampleTotal++; mAggregateTotal += value; diff --git a/external/3rd/library/soePlatform/CSAssist/utils/Base/win32/BlockAllocator.cpp b/external/3rd/library/soePlatform/CSAssist/utils/Base/win32/BlockAllocator.cpp index 9fa8b645..fe891286 100644 --- a/external/3rd/library/soePlatform/CSAssist/utils/Base/win32/BlockAllocator.cpp +++ b/external/3rd/library/soePlatform/CSAssist/utils/Base/win32/BlockAllocator.cpp @@ -1,111 +1,111 @@ #include "../BlockAllocator.h" #ifdef EXTERNAL_DISTRO -namespace NAMESPACE +namespace NAMESPACE { #endif -namespace Base -{ - - BlockAllocator::BlockAllocator() + namespace Base { - for(unsigned i = 0; i < 31; i++) - { - m_blocks[i] = NULL; - } - } - BlockAllocator::~BlockAllocator() - { - // free all allocated memory blocks - for(unsigned i = 0; i < 31; i++) + BlockAllocator::BlockAllocator() { - while(m_blocks[i] != NULL) + for (unsigned i = 0; i < 31; i++) { - unsigned *tmp = m_blocks[i]; - m_blocks[i] = (unsigned *)*m_blocks[i]; - free(tmp); + m_blocks[i] = NULL; } } - } -// Allocate a block that is the next power of two greater than the # of bytes passed. -// 33 bytes yields a 64 byte block of memory and so forth. - - void *BlockAllocator::getBlock(unsigned bytes) - { - unsigned accum = 16, bits = 16; - unsigned *handle = NULL; - - // Perform a binary search looking for the highest bit. - - while(bits != 0) + BlockAllocator::~BlockAllocator() { - // If bytes is less than the bit we're testing for, subtract half - // from the bit value and repeat - if(bytes < (unsigned)(1 << accum)) + // free all allocated memory blocks + for (unsigned i = 0; i < 31; i++) { - bits /= 2; - accum -= bits; + while (m_blocks[i] != NULL) + { + uintptr_t *tmp = m_blocks[i]; + m_blocks[i] = (uintptr_t *)*m_blocks[i]; + free(tmp); + } } - // If bytes is greater than the bit we're testing for, add half - // from the but value and repeat - else if(bytes > (unsigned)(1 << accum)) + } + + // Allocate a block that is the next power of two greater than the # of bytes passed. + // 33 bytes yields a 64 byte block of memory and so forth. + + void *BlockAllocator::getBlock(unsigned bytes) + { + unsigned accum = 16, bits = 16; + uintptr_t *handle = NULL; + + // Perform a binary search looking for the highest bit. + + while (bits != 0) { - bits /= 2; - accum += bits; + // If bytes is less than the bit we're testing for, subtract half + // from the bit value and repeat + if (bytes < (unsigned)(1 << accum)) + { + bits /= 2; + accum -= bits; + } + // If bytes is greater than the bit we're testing for, add half + // from the but value and repeat + else if (bytes >(unsigned)(1 << accum)) + { + bits /= 2; + accum += bits; + } + // Got lucky and hit the value dead on + else + { + break; + } + } + // At this point accum contains the most significant bit index, increment + accum++; + if (accum < 2) + { + accum = 2; + } + + // Note that when memory is actually allocated, 8 extra bytes will be allocated.at the front + // The first integer is the address of the next block of memory when the block is in the allocator + // The second integer is the bit length of the block + // Memory is allocated on 4 byte boundaries to sidestep byte alignment problems + + + // Check if the allocator already has a block of that size + if (m_blocks[accum] == 0) + { + // remove the pre allocated block from the linked list + handle = (uintptr_t *)calloc(((1 << accum) / 4) + 2, sizeof(uintptr_t)); + handle[1] = accum; + handle[0] = 0; } - // Got lucky and hit the value dead on else { - break; + // Allocate a new block + handle = m_blocks[accum]; + m_blocks[accum] = (uintptr_t *)handle[0]; + handle[0] = 0; + } + // return a pointer that skips over the header used for the allocator's purposes + return(handle + 2); + } + + void BlockAllocator::returnBlock(uintptr_t *handle) + { + // C++ allows for safe deletion of a NULL pointer + if (handle) + { + // Update the allocator linked list, insert this entry at the head + *(handle - 2) = (uintptr_t)m_blocks[*(handle - 1)]; + // Add this entry to the proper linked list node + m_blocks[*(handle - 1)] = (handle - 2); } } - // At this point accum contains the most significant bit index, increment - accum++; - if(accum < 2) - { - accum = 2; - } - - // Note that when memory is actually allocated, 8 extra bytes will be allocated.at the front - // The first integer is the address of the next block of memory when the block is in the allocator - // The second integer is the bit length of the block - // Memory is allocated on 4 byte boundaries to sidestep byte alignment problems - - - // Check if the allocator already has a block of that size - if(m_blocks[accum] == 0) - { - // remove the pre allocated block from the linked list - handle = (unsigned *)calloc(((1 << accum) / 4) + 2, sizeof(unsigned)); - handle[1] = accum; - handle[0] = 0; - } - else - { - // Allocate a new block - handle = m_blocks[accum]; - m_blocks[accum] = (unsigned *)handle[0]; - handle[0] = 0; - } - // return a pointer that skips over the header used for the allocator's purposes - return(handle + 2); - } - - void BlockAllocator::returnBlock(unsigned *handle) - { - // C++ allows for safe deletion of a NULL pointer - if(handle) - { - // Update the allocator linked list, insert this entry at the head - *(handle - 2) = (unsigned)m_blocks[*(handle - 1)]; - // Add this entry to the proper linked list node - m_blocks[*(handle - 1)] = (handle - 2); - } - } -}; + }; #ifdef EXTERNAL_DISTRO }; #endif diff --git a/external/3rd/library/soePlatform/ChatAPI/utils/Base/BlockAllocator.h b/external/3rd/library/soePlatform/ChatAPI/utils/Base/BlockAllocator.h index 5daf69da..bbfbf273 100644 --- a/external/3rd/library/soePlatform/ChatAPI/utils/Base/BlockAllocator.h +++ b/external/3rd/library/soePlatform/ChatAPI/utils/Base/BlockAllocator.h @@ -20,7 +20,7 @@ namespace Base void returnBlock(unsigned *handle); private: - unsigned *m_blocks[31]; + uintptr_t *m_blocks[31]; }; }; #ifdef EXTERNAL_DISTRO diff --git a/external/3rd/library/soePlatform/ChatAPI/utils/Base/win32/BlockAllocator.cpp b/external/3rd/library/soePlatform/ChatAPI/utils/Base/win32/BlockAllocator.cpp index 9fa8b645..fe891286 100644 --- a/external/3rd/library/soePlatform/ChatAPI/utils/Base/win32/BlockAllocator.cpp +++ b/external/3rd/library/soePlatform/ChatAPI/utils/Base/win32/BlockAllocator.cpp @@ -1,111 +1,111 @@ #include "../BlockAllocator.h" #ifdef EXTERNAL_DISTRO -namespace NAMESPACE +namespace NAMESPACE { #endif -namespace Base -{ - - BlockAllocator::BlockAllocator() + namespace Base { - for(unsigned i = 0; i < 31; i++) - { - m_blocks[i] = NULL; - } - } - BlockAllocator::~BlockAllocator() - { - // free all allocated memory blocks - for(unsigned i = 0; i < 31; i++) + BlockAllocator::BlockAllocator() { - while(m_blocks[i] != NULL) + for (unsigned i = 0; i < 31; i++) { - unsigned *tmp = m_blocks[i]; - m_blocks[i] = (unsigned *)*m_blocks[i]; - free(tmp); + m_blocks[i] = NULL; } } - } -// Allocate a block that is the next power of two greater than the # of bytes passed. -// 33 bytes yields a 64 byte block of memory and so forth. - - void *BlockAllocator::getBlock(unsigned bytes) - { - unsigned accum = 16, bits = 16; - unsigned *handle = NULL; - - // Perform a binary search looking for the highest bit. - - while(bits != 0) + BlockAllocator::~BlockAllocator() { - // If bytes is less than the bit we're testing for, subtract half - // from the bit value and repeat - if(bytes < (unsigned)(1 << accum)) + // free all allocated memory blocks + for (unsigned i = 0; i < 31; i++) { - bits /= 2; - accum -= bits; + while (m_blocks[i] != NULL) + { + uintptr_t *tmp = m_blocks[i]; + m_blocks[i] = (uintptr_t *)*m_blocks[i]; + free(tmp); + } } - // If bytes is greater than the bit we're testing for, add half - // from the but value and repeat - else if(bytes > (unsigned)(1 << accum)) + } + + // Allocate a block that is the next power of two greater than the # of bytes passed. + // 33 bytes yields a 64 byte block of memory and so forth. + + void *BlockAllocator::getBlock(unsigned bytes) + { + unsigned accum = 16, bits = 16; + uintptr_t *handle = NULL; + + // Perform a binary search looking for the highest bit. + + while (bits != 0) { - bits /= 2; - accum += bits; + // If bytes is less than the bit we're testing for, subtract half + // from the bit value and repeat + if (bytes < (unsigned)(1 << accum)) + { + bits /= 2; + accum -= bits; + } + // If bytes is greater than the bit we're testing for, add half + // from the but value and repeat + else if (bytes >(unsigned)(1 << accum)) + { + bits /= 2; + accum += bits; + } + // Got lucky and hit the value dead on + else + { + break; + } + } + // At this point accum contains the most significant bit index, increment + accum++; + if (accum < 2) + { + accum = 2; + } + + // Note that when memory is actually allocated, 8 extra bytes will be allocated.at the front + // The first integer is the address of the next block of memory when the block is in the allocator + // The second integer is the bit length of the block + // Memory is allocated on 4 byte boundaries to sidestep byte alignment problems + + + // Check if the allocator already has a block of that size + if (m_blocks[accum] == 0) + { + // remove the pre allocated block from the linked list + handle = (uintptr_t *)calloc(((1 << accum) / 4) + 2, sizeof(uintptr_t)); + handle[1] = accum; + handle[0] = 0; } - // Got lucky and hit the value dead on else { - break; + // Allocate a new block + handle = m_blocks[accum]; + m_blocks[accum] = (uintptr_t *)handle[0]; + handle[0] = 0; + } + // return a pointer that skips over the header used for the allocator's purposes + return(handle + 2); + } + + void BlockAllocator::returnBlock(uintptr_t *handle) + { + // C++ allows for safe deletion of a NULL pointer + if (handle) + { + // Update the allocator linked list, insert this entry at the head + *(handle - 2) = (uintptr_t)m_blocks[*(handle - 1)]; + // Add this entry to the proper linked list node + m_blocks[*(handle - 1)] = (handle - 2); } } - // At this point accum contains the most significant bit index, increment - accum++; - if(accum < 2) - { - accum = 2; - } - - // Note that when memory is actually allocated, 8 extra bytes will be allocated.at the front - // The first integer is the address of the next block of memory when the block is in the allocator - // The second integer is the bit length of the block - // Memory is allocated on 4 byte boundaries to sidestep byte alignment problems - - - // Check if the allocator already has a block of that size - if(m_blocks[accum] == 0) - { - // remove the pre allocated block from the linked list - handle = (unsigned *)calloc(((1 << accum) / 4) + 2, sizeof(unsigned)); - handle[1] = accum; - handle[0] = 0; - } - else - { - // Allocate a new block - handle = m_blocks[accum]; - m_blocks[accum] = (unsigned *)handle[0]; - handle[0] = 0; - } - // return a pointer that skips over the header used for the allocator's purposes - return(handle + 2); - } - - void BlockAllocator::returnBlock(unsigned *handle) - { - // C++ allows for safe deletion of a NULL pointer - if(handle) - { - // Update the allocator linked list, insert this entry at the head - *(handle - 2) = (unsigned)m_blocks[*(handle - 1)]; - // Add this entry to the proper linked list node - m_blocks[*(handle - 1)] = (handle - 2); - } - } -}; + }; #ifdef EXTERNAL_DISTRO }; #endif