-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <dice/template-library/pool_allocator.hpp> | ||
|
||
#include <cstdint> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
struct list { | ||
uint64_t elem; | ||
list *next; | ||
}; | ||
|
||
int main() { | ||
dice::template_library::pool<sizeof(list)> pool; | ||
|
||
{ // efficient pool allocations for elements of known size | ||
auto list_alloc = pool.get_allocator<list>(); | ||
|
||
auto *head = list_alloc.allocate(1); // efficient pool allocation | ||
new (head) list{.elem = 0, .next = nullptr}; | ||
|
||
head->next = list_alloc.allocate(1); // efficient pool allocation | ||
new (head->next) list{.elem = 1, .next = nullptr}; | ||
|
||
auto const *cur = head; | ||
while (cur != nullptr) { | ||
std::cout << cur->elem << " "; | ||
cur = cur->next; | ||
} | ||
|
||
list_alloc.deallocate(head->next, 1); | ||
list_alloc.deallocate(head, 1); | ||
} | ||
|
||
{ // fallback allocation with new & support as container allocator | ||
std::vector<uint64_t, dice::template_library::pool_allocator<uint64_t, sizeof(list)>> vec(pool.get_allocator()); | ||
vec.resize(1024); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters