-
Notifications
You must be signed in to change notification settings - Fork 0
minor performance optimization implementations #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8c3d57d
9139454
1c7099e
8fe2fbe
8d075c4
d53560e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| # Dotfiles and system files | ||
| .idea/ | ||
| .vscode/ | ||
| .cache/ | ||
| .DS_Store | ||
|
|
||
| build/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,12 +10,39 @@ The simulator allows users to test various trading strategies, analyze market da | |||
| - Order cancellation | ||||
| - Feed publishing and subscription | ||||
| - Trade execution simulation | ||||
| - Lock-free multi-producer single-consumer (MPSC) queue for high-performance message passing | ||||
| - Basic logging functionality | ||||
|
|
||||
|
|
||||
| ## Things that can be improved | ||||
| ## Things to work on / TODOs | ||||
| - Performance optimizations (order matching and execution) | ||||
| - Price representation as floats (should be a "Money" type) | ||||
| - More sophisticated order types (e.g., stop-loss, iceberg orders) | ||||
| - Enhanced logging and monitoring capabilities | ||||
|
|
||||
| # Potential future features | ||||
| - Integration with real market data feeds | ||||
| - Support for additional asset classes (e.g., options, futures) | ||||
| - Advanced analytics and reporting tools | ||||
| - | ||||
|
||||
| - |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||
| #ifndef MEMORY_POOL_H | ||||||
| #define MEMORY_POOL_H | ||||||
| #include <iostream> | ||||||
ThePyLord marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| #include <cstddef> | ||||||
| #include <cstdint> | ||||||
| #include <memory> | ||||||
|
|
||||||
| template <typename T> | ||||||
| class MemoryPool { | ||||||
| public: | ||||||
| explicit MemoryPool(size_t pool_size = 1024): pool_size_(pool_size) { | ||||||
| pool_ = std::make_unique<Slot[]>(pool_size_); | ||||||
| init_free_list(); | ||||||
| }; | ||||||
|
|
||||||
| ~MemoryPool() {}; | ||||||
|
|
||||||
| template<typename... Args> | ||||||
| T* allocate(Args&&... args) { | ||||||
| if(!head) | ||||||
| return nullptr; | ||||||
| Slot* curr = head; | ||||||
| head = head->next; | ||||||
| return new (&curr->data) T(std::forward<Args>(args)...); // Pool exhausted | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * Marks a pooled object slot as free so it can be reused. | ||||||
| * @param obj Pointer previously obtained from this pool's allocate(). Must point | ||||||
| * into the memory block returned by pool_.get(). | ||||||
| * See also: allocate() | ||||||
| */ | ||||||
| void deallocate(T* obj) { | ||||||
|
|
||||||
| if(!obj) | ||||||
| return; | ||||||
| obj->~T(); | ||||||
|
|
||||||
| Slot* curr = reinterpret_cast<Slot*>(obj); | ||||||
| // Set the current slot to the top of the free list | ||||||
| curr->next = head; | ||||||
| head = curr; | ||||||
| }; | ||||||
|
|
||||||
| private: | ||||||
| // Storage | ||||||
| union Slot { | ||||||
| T data; | ||||||
| Slot* next; | ||||||
| }; | ||||||
| std::unique_ptr<Slot[]> pool_; | ||||||
| // free list | ||||||
| Slot* head; | ||||||
| // In-use buffer | ||||||
| bool* in_use_; | ||||||
|
Comment on lines
+54
to
+55
|
||||||
| // In-use buffer | |
| bool* in_use_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gtest_discover_tests call at line 112 incorrectly uses the PRIVATE keyword which is not a valid argument for this function. This should be removed as gtest_discover_tests doesn't accept visibility specifiers.