diff options
author | 2012-01-13 11:14:05 -0800 | |
---|---|---|
committer | 2012-01-13 11:14:05 -0800 | |
commit | 4341d5ef32b4e723a35f1b037efb02eb369a97b8 (patch) | |
tree | 2853daa99192ba6585c315fdf293e627125fbd5b /native/src/words_priority_queue_pool.h | |
parent | 6a381444fa68fd925b555d03cc186ac36ea4fa35 (diff) | |
parent | b960477952101633d053b459e669db46d3234ac3 (diff) | |
download | latinime-4341d5ef32b4e723a35f1b037efb02eb369a97b8.tar.gz latinime-4341d5ef32b4e723a35f1b037efb02eb369a97b8.tar.xz latinime-4341d5ef32b4e723a35f1b037efb02eb369a97b8.zip |
am b9604779: Use placement new to construct the queue
* commit 'b960477952101633d053b459e669db46d3234ac3':
Use placement new to construct the queue
Diffstat (limited to 'native/src/words_priority_queue_pool.h')
-rw-r--r-- | native/src/words_priority_queue_pool.h | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/native/src/words_priority_queue_pool.h b/native/src/words_priority_queue_pool.h index 386297650..bf9619e19 100644 --- a/native/src/words_priority_queue_pool.h +++ b/native/src/words_priority_queue_pool.h @@ -17,6 +17,8 @@ #ifndef LATINIME_WORDS_PRIORITY_QUEUE_POOL_H #define LATINIME_WORDS_PRIORITY_QUEUE_POOL_H +#include <assert.h> +#include <new> #include "words_priority_queue.h" namespace latinime { @@ -24,30 +26,45 @@ namespace latinime { class WordsPriorityQueuePool { public: WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) { - mMasterQueue = new WordsPriorityQueue(mainQueueMaxWords, maxWordLength); - mSubQueue1 = new WordsPriorityQueue(subQueueMaxWords, maxWordLength); - mSubQueue2 = new WordsPriorityQueue(subQueueMaxWords, maxWordLength); + mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength); + for (int i = 0, subQueueBufOffset = 0; i < SUB_QUEUE_MAX_COUNT; + ++i, subQueueBufOffset += sizeof(WordsPriorityQueue)) { + mSubQueues1[i] = new(mSubQueueBuf1 + subQueueBufOffset) + WordsPriorityQueue(subQueueMaxWords, maxWordLength); + mSubQueues2[i] = new(mSubQueueBuf2 + subQueueBufOffset) + WordsPriorityQueue(subQueueMaxWords, maxWordLength); + } } - ~WordsPriorityQueuePool() { - delete mMasterQueue; + virtual ~WordsPriorityQueuePool() { } WordsPriorityQueue* getMasterQueue() { return mMasterQueue; } + // TODO: Come up with more generic pool - WordsPriorityQueue* getSubQueue1() { - return mSubQueue1; + WordsPriorityQueue* getSubQueue1(const int id) { + if (DEBUG_WORDS_PRIORITY_QUEUE) { + assert(id >= 0 && id < SUB_QUEUE_MAX_COUNT); + } + return mSubQueues1[id]; } - WordsPriorityQueue* getSubQueue2() { - return mSubQueue2; + + WordsPriorityQueue* getSubQueue2(const int id) { + if (DEBUG_WORDS_PRIORITY_QUEUE) { + assert(id >= 0 && id < SUB_QUEUE_MAX_COUNT); + } + return mSubQueues2[id]; } private: - WordsPriorityQueue *mMasterQueue; - WordsPriorityQueue *mSubQueue1; - WordsPriorityQueue *mSubQueue2; + WordsPriorityQueue* mMasterQueue; + WordsPriorityQueue* mSubQueues1[SUB_QUEUE_MAX_COUNT]; + WordsPriorityQueue* mSubQueues2[SUB_QUEUE_MAX_COUNT]; + char mMasterQueueBuf[sizeof(WordsPriorityQueue)]; + char mSubQueueBuf1[SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; + char mSubQueueBuf2[SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; }; } |