XU XUv0.16.0

#core/alloc

import: #core/alloc

counts: 9 functions, 29 methods, 7 types, 1 constants, 1 method sets

Standard library package `#core/alloc`.

const BUDDY_MAX_ORDER

XuAPI
pub const BUDDY_MAX_ORDER = 10

Purpose

Constant BUDDY_MAX_ORDER, defining protocol or algorithm parameters.

struct Layout

XuAPI
pub struct Layout {
    pub size int
    pub align int
}

Purpose

Structure encapsulating size, align.

Public fields

size int
field (int)
align int
field (int)

layout_new

XuAPI
pub fn layout_new(size int, align int) Layout

Purpose

Layout new.

Parameters

size int
size (int)
align int
align (int)

Returns

Layout — a value of this type

struct@ GlobalAlloc

XuAPI
pub struct@ GlobalAlloc {
    fn alloc(Layout) *raw u8
    fn dealloc(*raw u8, Layout)
}

Purpose

Method-set constraint GlobalAlloc.

Required methods

alloc fn alloc(Layout) *raw u8
Execute alloc on GlobalAlloc.
dealloc fn dealloc(*raw u8, Layout)
Execute dealloc on GlobalAlloc.

(GlobalAlloc) alloc

XuAPI
fn alloc(Layout) *raw u8

Purpose

Execute alloc on GlobalAlloc.

Parameters

self Self
The Self instance used by this call (value receiver).
layout Layout
layout (Layout)

Returns

*raw u8 — a value of this type

(GlobalAlloc) dealloc

XuAPI
fn dealloc(*raw u8, Layout)

Purpose

Execute dealloc on GlobalAlloc.

Parameters

self Self
The Self instance used by this call (value receiver).
v *raw u8
value (*raw u8)
layout Layout
layout (Layout)

Returns

This call does not return a value.

is_power_of_two

XuAPI
pub fn is_power_of_two(n usize) bool

Purpose

Whether it is power of two.

Parameters

n usize
count, length, or limit (usize)

Returns

bool — true or false

align_up

XuAPI
pub fn align_up(addr usize, align usize) usize

Purpose

Align up.

Parameters

addr usize
address (usize)
align usize
align (usize)

Returns

usize — a value of this type

align_down

XuAPI
pub fn align_down(addr usize, align usize) usize

Purpose

Align down.

Parameters

addr usize
address (usize)
align usize
align (usize)

Returns

usize — a value of this type

(Layout) byte_size

XuAPI
pub fn (l Layout) byte_size() usize

Purpose

Operation on Layout: byte size.

Parameters

l Layout
The Layout instance used by this call (value receiver).

Returns

usize — a value of this type

(Layout) byte_align

XuAPI
pub fn (l Layout) byte_align() usize

Purpose

Operation on Layout: byte align.

Parameters

l Layout
The Layout instance used by this call (value receiver).

Returns

usize — a value of this type

(Layout) is_valid

XuAPI
pub fn (l Layout) is_valid() bool

Purpose

Operation on Layout: whether it is valid.

Parameters

l Layout
The Layout instance used by this call (value receiver).

Returns

bool — true or false

struct BumpAllocator

XuAPI
pub struct BumpAllocator {
    pub base usize
    pub limit usize
    pub cursor usize
    pub allocs usize
}

Purpose

Structure encapsulating base, limit, cursor, allocs.

Public fields

base usize
numeric base
limit usize
field (usize)
cursor usize
field (usize)
allocs usize
field (usize)

bump_init

XuAPI
pub fn bump_init(a *raw BumpAllocator, base *raw u8, size usize)

Purpose

Bump init.

Parameters

a *raw BumpAllocator
value (*raw BumpAllocator)
base *raw u8
numeric base (*raw u8)
size usize
size (usize)

Returns

This call does not return a value.

($&BumpAllocator) alloc_raw

XuAPI
pub fn (a $&BumpAllocator) alloc_raw(size usize, align usize) *raw u8

Purpose

Operation on $&BumpAllocator: alloc raw.

Parameters

a $&BumpAllocator
The BumpAllocator instance used by this call (exclusive borrow).
size usize
size (usize)
align usize
align (usize)

Returns

*raw u8 — a value of this type

($&BumpAllocator) alloc_zeroed

XuAPI
pub fn (a $&BumpAllocator) alloc_zeroed(size usize, align usize) *raw u8

Purpose

Operation on $&BumpAllocator: alloc zeroed.

Parameters

a $&BumpAllocator
The BumpAllocator instance used by this call (exclusive borrow).
size usize
size (usize)
align usize
align (usize)

Returns

*raw u8 — a value of this type

($&BumpAllocator) alloc

XuAPI
pub fn (a $&BumpAllocator) alloc(layout Layout) *raw u8

Purpose

Execute alloc on $&BumpAllocator.

Parameters

a $&BumpAllocator
The BumpAllocator instance used by this call (exclusive borrow).
layout Layout
layout (Layout)

Returns

*raw u8 — a value of this type

($&BumpAllocator) dealloc

XuAPI
pub fn (a $&BumpAllocator) dealloc(ptr *raw u8, layout Layout)

Purpose

Execute dealloc on $&BumpAllocator.

Parameters

a $&BumpAllocator
The BumpAllocator instance used by this call (exclusive borrow).
ptr *raw u8
ptr (*raw u8)
layout Layout
layout (Layout)

Returns

This call does not return a value.

($&BumpAllocator) reset

XuAPI
pub fn (a $&BumpAllocator) reset()

Purpose

Operation on $&BumpAllocator: clear internal state so the value can be reused.

Parameters

a $&BumpAllocator
The BumpAllocator instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&BumpAllocator) used

XuAPI
pub fn (a &BumpAllocator) used() usize

Purpose

Execute used on &BumpAllocator.

Parameters

a &BumpAllocator
The BumpAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&BumpAllocator) remaining

XuAPI
pub fn (a &BumpAllocator) remaining() usize

Purpose

Execute remaining on &BumpAllocator.

Parameters

a &BumpAllocator
The BumpAllocator instance used by this call (borrow).

Returns

usize — a value of this type

struct FixedPoolAllocator

XuAPI
pub struct FixedPoolAllocator {
    pub base usize
    pub end usize
    pub slot_size usize
    pub capacity usize
    pub free_head usize
    pub free_count usize
}

Purpose

Structure encapsulating base, end, slot_size, capacity, free_head.

Public fields

base usize
numeric base
end usize
field (usize)
slot_size usize
field (usize)
capacity usize
field (usize)
free_head usize
field (usize)
free_count usize
field (usize)

fixed_pool_init

XuAPI
pub fn fixed_pool_init(p *raw FixedPoolAllocator, mem_base *raw u8, mem_bytes usize, slot_size usize, slot_align usize) usize

Purpose

Fixed pool init.

Parameters

p *raw FixedPoolAllocator
p (*raw FixedPoolAllocator)
mem_base *raw u8
mem_base (*raw u8)
mem_bytes usize
mem_bytes (usize)
slot_size usize
slot_size (usize)
slot_align usize
slot_align (usize)

Returns

usize — a value of this type

($&FixedPoolAllocator) alloc_slot

XuAPI
pub fn (p $&FixedPoolAllocator) alloc_slot() *raw u8

Purpose

Operation on $&FixedPoolAllocator: alloc slot.

Parameters

p $&FixedPoolAllocator
The FixedPoolAllocator instance used by this call (exclusive borrow).

Returns

*raw u8 — a value of this type

($&FixedPoolAllocator) free_slot

XuAPI
pub fn (p $&FixedPoolAllocator) free_slot(ptr *raw u8) bool

Purpose

Operation on $&FixedPoolAllocator: free slot.

Parameters

p $&FixedPoolAllocator
The FixedPoolAllocator instance used by this call (exclusive borrow).
ptr *raw u8
ptr (*raw u8)

Returns

bool — true or false

(&FixedPoolAllocator) available

XuAPI
pub fn (p &FixedPoolAllocator) available() usize

Purpose

Execute available on &FixedPoolAllocator.

Parameters

p &FixedPoolAllocator
The FixedPoolAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&FixedPoolAllocator) in_use

XuAPI
pub fn (p &FixedPoolAllocator) in_use() usize

Purpose

Operation on &FixedPoolAllocator: in use.

Parameters

p &FixedPoolAllocator
The FixedPoolAllocator instance used by this call (borrow).

Returns

usize — a value of this type

struct LinkedListAllocator

XuAPI
pub struct LinkedListAllocator {
    pub base usize
    pub end usize
    pub head usize
    pub bytes_used usize
    pub bytes_free usize
    pub block_count usize
    pub alloc_count usize
    pub free_count usize
}

Purpose

Structure encapsulating base, end, head, bytes_used, bytes_free.

Public fields

base usize
numeric base
end usize
field (usize)
head usize
field (usize)
bytes_used usize
field (usize)
bytes_free usize
field (usize)
block_count usize
field (usize)
alloc_count usize
field (usize)
free_count usize
field (usize)

linked_list_init

XuAPI
pub fn linked_list_init(a *raw LinkedListAllocator, base *raw u8, size usize) bool

Purpose

Linked list init.

Parameters

a *raw LinkedListAllocator
value (*raw LinkedListAllocator)
base *raw u8
numeric base (*raw u8)
size usize
size (usize)

Returns

bool — true or false

($&LinkedListAllocator) alloc_raw

XuAPI
pub fn (a $&LinkedListAllocator) alloc_raw(size usize, align usize) *raw u8

Purpose

Operation on $&LinkedListAllocator: alloc raw.

Parameters

a $&LinkedListAllocator
The LinkedListAllocator instance used by this call (exclusive borrow).
size usize
size (usize)
align usize
align (usize)

Returns

*raw u8 — a value of this type

($&LinkedListAllocator) alloc_zeroed

XuAPI
pub fn (a $&LinkedListAllocator) alloc_zeroed(size usize, align usize) *raw u8

Purpose

Operation on $&LinkedListAllocator: alloc zeroed.

Parameters

a $&LinkedListAllocator
The LinkedListAllocator instance used by this call (exclusive borrow).
size usize
size (usize)
align usize
align (usize)

Returns

*raw u8 — a value of this type

($&LinkedListAllocator) dealloc_raw

XuAPI
pub fn (a $&LinkedListAllocator) dealloc_raw(ptr *raw u8) bool

Purpose

Operation on $&LinkedListAllocator: dealloc raw.

Parameters

a $&LinkedListAllocator
The LinkedListAllocator instance used by this call (exclusive borrow).
ptr *raw u8
ptr (*raw u8)

Returns

bool — true or false

($&LinkedListAllocator) alloc

XuAPI
pub fn (a $&LinkedListAllocator) alloc(layout Layout) *raw u8

Purpose

Execute alloc on $&LinkedListAllocator.

Parameters

a $&LinkedListAllocator
The LinkedListAllocator instance used by this call (exclusive borrow).
layout Layout
layout (Layout)

Returns

*raw u8 — a value of this type

($&LinkedListAllocator) dealloc

XuAPI
pub fn (a $&LinkedListAllocator) dealloc(ptr *raw u8, layout Layout)

Purpose

Execute dealloc on $&LinkedListAllocator.

Parameters

a $&LinkedListAllocator
The LinkedListAllocator instance used by this call (exclusive borrow).
ptr *raw u8
ptr (*raw u8)
layout Layout
layout (Layout)

Returns

This call does not return a value.

(&LinkedListAllocator) used

XuAPI
pub fn (a &LinkedListAllocator) used() usize

Purpose

Execute used on &LinkedListAllocator.

Parameters

a &LinkedListAllocator
The LinkedListAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&LinkedListAllocator) free_bytes

XuAPI
pub fn (a &LinkedListAllocator) free_bytes() usize

Purpose

Operation on &LinkedListAllocator: free bytes.

Parameters

a &LinkedListAllocator
The LinkedListAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&LinkedListAllocator) blocks

XuAPI
pub fn (a &LinkedListAllocator) blocks() usize

Purpose

Execute blocks on &LinkedListAllocator.

Parameters

a &LinkedListAllocator
The LinkedListAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&LinkedListAllocator) allocs

XuAPI
pub fn (a &LinkedListAllocator) allocs() usize

Purpose

Execute allocs on &LinkedListAllocator.

Parameters

a &LinkedListAllocator
The LinkedListAllocator instance used by this call (borrow).

Returns

usize — a value of this type

(&LinkedListAllocator) frees

XuAPI
pub fn (a &LinkedListAllocator) frees() usize

Purpose

Execute frees on &LinkedListAllocator.

Parameters

a &LinkedListAllocator
The LinkedListAllocator instance used by this call (borrow).

Returns

usize — a value of this type

struct BuddyBlock

XuAPI
pub struct BuddyBlock {
    pub next u64
    pub prev u64
}

Purpose

Structure encapsulating next, prev.

Public fields

next u64
field (u64)
prev u64
field (u64)

struct BuddyAllocator

XuAPI
pub struct BuddyAllocator {
    pub base u64
    pub total_pages usize
    pub free_pages usize
    pub max_order int
    pub pad0 u32
    pub free_lists [11]u64
}

Purpose

Structure encapsulating base, total_pages, free_pages, max_order, pad0.

Public fields

base u64
numeric base
total_pages usize
field (usize)
free_pages usize
field (usize)
max_order int
field (int)
pad0 u32
field (u32)
free_lists [11]u64
field ([11]u64)

buddy_init

XuAPI
pub fn buddy_init(b *raw BuddyAllocator, base u64, num_pages usize) bool

Purpose

Buddy init.

Parameters

b *raw BuddyAllocator
b (*raw BuddyAllocator)
base u64
numeric base (u64)
num_pages usize
num_pages (usize)

Returns

bool — true or false

($&BuddyAllocator) alloc_order

XuAPI
pub fn (b $&BuddyAllocator) alloc_order(order int) u64

Purpose

Operation on $&BuddyAllocator: alloc order.

Parameters

b $&BuddyAllocator
The BuddyAllocator instance used by this call (exclusive borrow).
order int
order (int)

Returns

u64 — a value of this type

($&BuddyAllocator) free_order

XuAPI
pub fn (b $&BuddyAllocator) free_order(addr u64, order int) bool

Purpose

Operation on $&BuddyAllocator: free order.

Parameters

b $&BuddyAllocator
The BuddyAllocator instance used by this call (exclusive borrow).
addr u64
address (u64)
order int
order (int)

Returns

bool — true or false

(&BuddyAllocator) free_page_count

XuAPI
pub fn (b &BuddyAllocator) free_page_count() usize

Purpose

Operation on &BuddyAllocator: free page count.

Parameters

b &BuddyAllocator
The BuddyAllocator instance used by this call (borrow).

Returns

usize — a value of this type

struct SlabAllocator

XuAPI
pub struct SlabAllocator {
    pub pools [8]FixedPoolAllocator
    pub base u64
    pub size usize
}

Purpose

Structure encapsulating pools, base, size.

Public fields

pools [8]FixedPoolAllocator
field ([8]FixedPoolAllocator)
base u64
numeric base
size usize
field (usize)

slab_init

XuAPI
pub fn slab_init(s *raw SlabAllocator, base *raw u8, total_bytes usize) bool

Purpose

Slab init.

Parameters

s *raw SlabAllocator
s (*raw SlabAllocator)
base *raw u8
numeric base (*raw u8)
total_bytes usize
total_bytes (usize)

Returns

bool — true or false

($&SlabAllocator) alloc_bytes

XuAPI
pub fn (s $&SlabAllocator) alloc_bytes(size usize) *raw u8

Purpose

Operation on $&SlabAllocator: alloc bytes.

Parameters

s $&SlabAllocator
The SlabAllocator instance used by this call (exclusive borrow).
size usize
size (usize)

Returns

*raw u8 — a value of this type

($&SlabAllocator) free_bytes

XuAPI
pub fn (s $&SlabAllocator) free_bytes(ptr *raw u8, size usize) bool

Purpose

Operation on $&SlabAllocator: free bytes.

Parameters

s $&SlabAllocator
The SlabAllocator instance used by this call (exclusive borrow).
ptr *raw u8
ptr (*raw u8)
size usize
size (usize)

Returns

bool — true or false