Content deleted Content added
Line 12:
<syntaxhighlight lang="cpp">
class
public:
void* allocate(size_t size) {
return ::operator new(size);
}
void deallocate(void* ptr) {
::operator delete(ptr);
}
};
struct ListNode {
Line 20 ⟶ 29:
};
Arena arena;
ListNode* head = nullptr;
for (int i = 1; i <= 1000; ++i) {
ListNode* newNode =
newNode->next = head;
head = newNode;
Line 30 ⟶ 40:
// (use list here)
// ...
arena.deallocate(head);
</syntaxhighlight>
Although it required many operations to construct the linked list, it can be quickly deallocated in a single operation by destroying the region (arena) in which the nodes were allocated. There is no need to traverse the list.
== Implementation ==
|