MySQL 9.1.0
Source Code Documentation
|
This class provides memory allocating and freeing methods for TranxNode. More...
#include <semisync_source.h>
Classes | |
struct | Block |
A sequence memory which contains BLOCK_TRANX_NODES TranxNodes. More... | |
Public Member Functions | |
TranxNodeAllocator (uint reserved_nodes) | |
~TranxNodeAllocator () | |
TranxNode * | allocate_node () |
The pointer of the first node after 'last_node' in current_block is returned. More... | |
int | free_all_nodes () |
All nodes are freed. More... | |
int | free_nodes_before (TranxNode *node) |
All Blocks before the given 'node' are free Block and moved into the rear of the Block link table. More... | |
Private Member Functions | |
int | allocate_block () |
Allocate a block and then assign it to current_block. More... | |
void | free_block (Block *block) |
Free a given Block. More... | |
void | free_blocks () |
If there are some free Blocks and the total number of the Blocks in the Block link table is larger than the 'reserved_blocks', Some free Blocks will be freed until the total number of the Blocks is equal to the 'reserved_blocks' or there is only one free Block behind the 'current_block'. More... | |
Private Attributes | |
uint | reserved_blocks |
Block * | first_block |
The 'first_block' is the head of the Block link table;. More... | |
Block * | last_block |
The 'last_block' is the rear of the Block link table;. More... | |
Block * | current_block |
current_block always points the Block in the Block link table in which the last allocated node is. More... | |
int | last_node |
It always points to the last node which has been allocated in the current_block. More... | |
uint | block_num |
How many Blocks are in the Block link table. More... | |
This class provides memory allocating and freeing methods for TranxNode.
The main target is performance.
The pointer of the first node after 'last_node' in current_block is returned. current_block will move to the next free Block when all nodes of it are in use. A new Block is allocated and is put into the rear of the Block link table if no Block is free.
The list starts up empty (ie, there is no allocated Block).
After some nodes are freed, there probably are some free nodes before the sequence of the allocated nodes, but we do not reuse it. It is better to keep the allocated nodes are in the sequence, for it is more efficient for allocating and freeing TranxNode.
There are two methods for freeing nodes. They are free_all_nodes and free_nodes_before.
'A Block is free' means all of its nodes are free.
As all allocated nodes are in the sequence, 'Before one node' means all nodes before given node in the same Block and all Blocks before the Block which containing the given node. As such, all Blocks before the given one ('node') are free Block and moved into the rear of the Block link table. The Block containing the given 'node', however, is not. For at least the given 'node' is still in use. This will waste at most one Block, but it is more efficient.
|
inline |
reserved_nodes | The number of reserved TranxNodes. It is used to set 'reserved_blocks' which can contain at least 'reserved_nodes' number of TranxNodes. When freeing memory, we will reserve at least reserved_blocks of Blocks not freed. |
|
inline |
|
inlineprivate |
Allocate a block and then assign it to current_block.
|
inline |
The pointer of the first node after 'last_node' in current_block is returned.
current_block will move to the next free Block when all nodes of it are in use. A new Block is allocated and is put into the rear of the Block link table if no Block is free.
|
inline |
All nodes are freed.
|
inlineprivate |
Free a given Block.
block | The Block will be freed. |
|
inlineprivate |
If there are some free Blocks and the total number of the Blocks in the Block link table is larger than the 'reserved_blocks', Some free Blocks will be freed until the total number of the Blocks is equal to the 'reserved_blocks' or there is only one free Block behind the 'current_block'.
|
inline |
All Blocks before the given 'node' are free Block and moved into the rear of the Block link table.
node | All nodes before 'node' will be freed |
|
private |
How many Blocks are in the Block link table.
|
private |
current_block always points the Block in the Block link table in which the last allocated node is.
The Blocks before it are all in use and the Blocks after it are all free.
|
private |
The 'first_block' is the head of the Block link table;.
|
private |
The 'last_block' is the rear of the Block link table;.
|
private |
It always points to the last node which has been allocated in the current_block.
|
private |