mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 15:09:31 +03:00
use uint8_t bit fields, and improve portability of page_flags type
This commit is contained in:
parent
72d1ab80c3
commit
26c27fbf58
2 changed files with 14 additions and 13 deletions
|
@ -132,15 +132,16 @@ typedef enum mi_delayed_e {
|
||||||
|
|
||||||
// The `in_full` and `has_aligned` page flags are put in a union to efficiently
|
// The `in_full` and `has_aligned` page flags are put in a union to efficiently
|
||||||
// test if both are false (`value == 0`) in the `mi_free` routine.
|
// test if both are false (`value == 0`) in the `mi_free` routine.
|
||||||
typedef union mi_page_flags_u {
|
typedef struct mi_page_flags_s {
|
||||||
uint16_t value;
|
#pragma warning(suppress:4201)
|
||||||
|
union {
|
||||||
uint8_t full_aligned;
|
uint8_t full_aligned;
|
||||||
struct { // force alignment
|
struct {
|
||||||
unsigned in_full:1;
|
uint8_t in_full : 1;
|
||||||
unsigned has_aligned:1;
|
uint8_t has_aligned : 1;
|
||||||
bool is_zero; // `true` if the blocks in the free list are zero initialized
|
|
||||||
#pragma warning(suppress:4201)
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
bool is_zero; // `true` if the blocks in the free list are zero initialized
|
||||||
} mi_page_flags_t;
|
} mi_page_flags_t;
|
||||||
|
|
||||||
// Thread free list.
|
// Thread free list.
|
||||||
|
@ -168,10 +169,10 @@ typedef uintptr_t mi_thread_free_t;
|
||||||
typedef struct mi_page_s {
|
typedef struct mi_page_s {
|
||||||
// "owned" by the segment
|
// "owned" by the segment
|
||||||
uint8_t segment_idx; // index in the segment `pages` array, `page == &segment->pages[page->segment_idx]`
|
uint8_t segment_idx; // index in the segment `pages` array, `page == &segment->pages[page->segment_idx]`
|
||||||
unsigned segment_in_use:1; // `true` if the segment allocated this page
|
uint8_t segment_in_use:1; // `true` if the segment allocated this page
|
||||||
unsigned is_reset:1; // `true` if the page memory was reset
|
uint8_t is_reset:1; // `true` if the page memory was reset
|
||||||
unsigned is_committed:1; // `true` if the page virtual memory is committed
|
uint8_t is_committed:1; // `true` if the page virtual memory is committed
|
||||||
unsigned is_zero_init:1; // `true` if the page was zero initialized
|
uint8_t is_zero_init:1; // `true` if the page was zero initialized
|
||||||
|
|
||||||
// layout like this to optimize access in `mi_malloc` and `mi_free`
|
// layout like this to optimize access in `mi_malloc` and `mi_free`
|
||||||
uint16_t capacity; // number of blocks committed, must be the first field, see `segment.c:page_clear`
|
uint16_t capacity; // number of blocks committed, must be the first field, see `segment.c:page_clear`
|
||||||
|
|
|
@ -13,7 +13,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
// Empty page used to initialize the small free pages array
|
// Empty page used to initialize the small free pages array
|
||||||
const mi_page_t _mi_page_empty = {
|
const mi_page_t _mi_page_empty = {
|
||||||
0, false, false, false, false, 0, 0,
|
0, false, false, false, false, 0, 0,
|
||||||
{ 0 },
|
{ { 0 }, false },
|
||||||
NULL, // free
|
NULL, // free
|
||||||
#if MI_SECURE
|
#if MI_SECURE
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue