Module dlmalloc stdlib

dlmalloc
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
1
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Imported by

This section is empty.

Aliases

This section is empty.

Constants

#constant n_small_bins

n_small_bins           = 32

#constant n_tree_bins

n_tree_bins            = 32

#constant small_bin_shift

small_bin_shift        = 3

#constant tree_bin_shift

tree_bin_shift         = 8

#constant max_release_check_rate

max_release_check_rate = 4095

Sum types

This section is empty.

Functions

#fn calloc

unsafe
fn calloc(size usize) voidptr

Same as malloc, except if the allocation succeeds it's guaranteed to point to size bytes of zeros.

#fn free

unsafe
fn free(ptr voidptr)

free deallocates a ptr.

#fn get_system_allocator

Windows
fn get_system_allocator() Allocator

#fn get_system_allocator

Linux
fn get_system_allocator() Allocator

#fn malloc

unsafe
fn malloc(size usize) voidptr

/ malloc allocates size bytes.

/ / Returns a null pointer if allocation fails. Returns a valid pointer / otherwise.

#fn memalign

unsafe
fn memalign(size usize, align usize) voidptr

memalign allocates size bytes with align align.

Returns a null pointer if allocation fails. Returns a valid pointer otherwise.

#fn new

fn new(system_allocator Allocator) Dlmalloc

#fn realloc

unsafe
fn realloc(ptr voidptr, oldsize usize, newsize usize) voidptr

realloc reallocates ptr, a previous allocation with old_size and to have new_size.

Returns a null pointer if the memory couldn't be reallocated, but ptr is still valid. Returns a valid pointer and frees ptr if the request is satisfied.

Structs

#struct Allocator

pub struct Allocator {
	alloc            fn (voidptr, usize) (voidptr, usize, u32)
	remap            fn (voidptr, voidptr, usize, usize, bool) voidptr
	free_part        fn (voidptr, voidptr, usize, usize) bool
	free_            fn (voidptr, voidptr, usize) bool
	can_release_part fn (voidptr, u32) bool
	allocates_zeros  fn (voidptr) bool
	page_size        fn (voidptr) usize // not a constant field because some platforms might have different page sizes depending on configs
	data             voidptr
}

In order for dlmalloc to efficently manage memory, it needs a way to communicate with the underlying platform.

This Allocator type provides an interface for this communication.

Why not interface? Interfaces require memory allocation so it is simpler to pass a struct.

#struct Dlmalloc

pub struct Dlmalloc {
	system_allocator Allocator
	max_request      usize = 4294901657
mut:
	// bin maps
	smallmap u32 // bin map for small bins
	treemap  u32 // bin map  for tree bins

	smallbins      [66]&Chunk // small bins, it is actually (n_small_bins + 1) * 2
	treebins       [n_tree_bins]&TreeChunk
	dvsize         usize
	topsize        usize
	dv             &Chunk = unsafe { nil }
	top            &Chunk = unsafe { nil }
	footprint      usize
	max_footprint  usize
	seg            Segment
	trim_check     u32
	least_addr     voidptr
	release_checks usize
}

#fn (&Dlmalloc) calloc_must_clear

unsafe
fn (dl &Dlmalloc) calloc_must_clear(ptr voidptr) bool

#fn (&Dlmalloc) smallbin_at

unsafe
fn (mut dl &Dlmalloc) smallbin_at(idx u32) &Chunk

#fn (&Dlmalloc) treebin_at

unsafe
fn (mut dl &Dlmalloc) treebin_at(idx u32) &TreeChunk

#fn (&Dlmalloc) compute_tree_index

fn (dl &Dlmalloc) compute_tree_index(size usize) u32

#fn (&Dlmalloc) calloc

unsafe
fn (mut dl &Dlmalloc) calloc(size usize) voidptr

calloc is the same as malloc, except if the allocation succeeds it's guaranteed to point to size bytes of zeros.

#fn (&Dlmalloc) free_

unsafe
fn (mut dl &Dlmalloc) free_(mem voidptr)

free_ behaves as libc free, but operates within the given space

#fn (&Dlmalloc) should_trim

fn (dl &Dlmalloc) should_trim(size usize) bool

#fn (&Dlmalloc) sys_trim

unsafe
fn (mut dl &Dlmalloc) sys_trim(pad_ usize) bool

#fn (&Dlmalloc) release_unused_segments

unsafe
fn (mut dl &Dlmalloc) release_unused_segments() usize

#fn (&Dlmalloc) replace_dv

unsafe
fn (mut dl &Dlmalloc) replace_dv(chunk &Chunk, size usize)

#fn (&Dlmalloc) insert_chunk

unsafe
fn (mut dl &Dlmalloc) insert_chunk(chunk &Chunk, size usize)

#fn (&Dlmalloc) insert_small_chunk

unsafe
fn (mut dl &Dlmalloc) insert_small_chunk(chunk_ &Chunk, size usize)

#fn (&Dlmalloc) insert_large_chunk

unsafe
fn (mut dl &Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size usize)

#fn (&Dlmalloc) clear_smallmap

unsafe
fn (mut dl &Dlmalloc) clear_smallmap(idx u32)

#fn (&Dlmalloc) mark_smallmap

unsafe
fn (mut dl &Dlmalloc) mark_smallmap(idx u32)

#fn (&Dlmalloc) smallmap_is_marked

unsafe
fn (mut dl &Dlmalloc) smallmap_is_marked(idx u32) bool

#fn (&Dlmalloc) clear_treemap

unsafe
fn (mut dl &Dlmalloc) clear_treemap(idx u32)

#fn (&Dlmalloc) mark_treemap

unsafe
fn (mut dl &Dlmalloc) mark_treemap(idx u32)

#fn (&Dlmalloc) treemap_is_marked

unsafe
fn (mut dl &Dlmalloc) treemap_is_marked(idx u32) bool

#fn (&Dlmalloc) malloc

fn (mut dl &Dlmalloc) malloc(size usize) voidptr

#fn (&Dlmalloc) malloc_real

unsafe
fn (mut dl &Dlmalloc) malloc_real(size usize) voidptr

/ malloc behaves as libc malloc, but operates within the given space

#fn (&Dlmalloc) init_bins

unsafe
fn (mut dl &Dlmalloc) init_bins()

#fn (&Dlmalloc) init_top

unsafe
fn (mut dl &Dlmalloc) init_top(ptr &Chunk, size_ usize)

#fn (&Dlmalloc) sys_alloc

unsafe
fn (mut dl &Dlmalloc) sys_alloc(size usize) voidptr

#fn (&Dlmalloc) tmalloc_small

unsafe
fn (mut dl &Dlmalloc) tmalloc_small(size usize) voidptr

#fn (&Dlmalloc) tmalloc_large

unsafe
fn (mut dl &Dlmalloc) tmalloc_large(size usize) voidptr

#fn (&Dlmalloc) prepend_alloc

unsafe
fn (mut dl &Dlmalloc) prepend_alloc(newbase voidptr, oldbase voidptr, size usize) voidptr

#fn (&Dlmalloc) add_segment

unsafe
fn (mut dl &Dlmalloc) add_segment(tbase voidptr, tsize usize, flags u32)

#fn (&Dlmalloc) segment_holding

unsafe
fn (mut dl &Dlmalloc) segment_holding(ptr voidptr) &Segment

#fn (&Dlmalloc) realloc

unsafe
fn (mut dl &Dlmalloc) realloc(oldmem voidptr, bytes usize) voidptr

realloc behaves as libc realloc, but operates within the given space

#fn (&Dlmalloc) memalign

unsafe
fn (mut dl &Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr

memaligns allocates memory aligned to alignment_. Only call this with power-of-two alignment and alignment > dlmalloc.malloc_alignment

#fn (&Dlmalloc) try_realloc_chunk

unsafe
fn (mut dl &Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chunk

#fn (&Dlmalloc) mmap_resize

unsafe
fn (mut dl &Dlmalloc) mmap_resize(oldp_ &Chunk, nb usize, can_move bool) &Chunk

#fn (&Dlmalloc) mmap_align

fn (dl &Dlmalloc) mmap_align(a usize) usize

#fn (&Dlmalloc) dispose_chunk

unsafe
fn (mut dl &Dlmalloc) dispose_chunk(p_ &Chunk, psize_ usize)

Interfaces

This section is empty.

Enums

#enum Mm_prot

Linux
pub enum Mm_prot {
	prot_read = 0x1
	prot_write = 0x2
	prot_exec = 0x4
	prot_none = 0x0
	prot_growsdown = 0x01000000
	prot_growsup = 0x02000000
}

#enum Map_flags

Linux
pub enum Map_flags {
	map_shared = 0x01
	map_private = 0x02
	map_shared_validate = 0x03
	map_type = 0x0f
	map_fixed = 0x10
	map_file = 0x00
	map_anonymous = 0x20
	map_huge_shift = 26
	map_huge_mask = 0x3f
}