# reservedmem

Dark Mode

- Manual
- Standard library
- Index

Search:
Group by:

Authors: | Zahary Karadjov

This module provides utilities for reserving a portions of the address space of a program without consuming physical memory. It can be used to implement a dynamically resizable buffer that is guaranteed to remain in the same memory location. The buffer will be able to grow up to the size of the initially reserved portion of the address space.

Unstable API.

# Imports

ospaths, winlean

# Types

    MemAccessFlags = int

  Source Edit

    ReservedMem = object
      memStart: pointer
      usedMemEnd: pointer
      committedMemEnd: pointer
      memEnd: pointer
      maxCommittedAndUnusedPages: int
      accessFlags: MemAccessFlags

  Source Edit

    ReservedMemSeq[T] = object
      mem: ReservedMem

  Source Edit

# Consts

    memExec = 16

  Source Edit

    memExecRead = 32

  Source Edit

    memExecReadWrite = 64

  Source Edit

    memRead = 2

  Source Edit

    memReadWrite = 4

  Source Edit

# Procs

    proc init(T: type ReservedMem; maxLen: Natural; initLen: Natural = 0;
              initCommitLen = initLen; memStart = pointer(nil);
              accessFlags = memReadWrite; maxCommittedAndUnusedPages = 3): ReservedMem

  Source Edit

    proc setLen(m: var ReservedMem; newLen: int) {...}{.raises: [OSError], tags: [].}

  Source Edit

    proc init(SeqType: type ReservedMemSeq; maxLen: Natural; initLen: Natural = 0;
              initCommitLen: Natural = 0; memStart = pointer(nil);
              accessFlags = memReadWrite; maxCommittedAndUnusedPages = 3): SeqType:type

  Source Edit

    proc setLen[T](s: var ReservedMemSeq[T]; newLen: int)

  Source Edit

    proc add[T](s: var ReservedMemSeq[T]; val: T)

  Source Edit

    proc pop[T](s: var ReservedMemSeq[T]): T

  Source Edit

# Funcs

    func len(m: ReservedMem): int {...}{.raises: [], tags: [].}

  Source Edit

    func commitedLen(m: ReservedMem): int {...}{.raises: [], tags: [].}

  Source Edit

    func maxLen(m: ReservedMem): int {...}{.raises: [], tags: [].}

  Source Edit

    func `[]`[T](s: ReservedMemSeq[T]; pos: Natural): lent T

  Source Edit

    func `[]`[T](s: var ReservedMemSeq[T]; pos: Natural): var T

  Source Edit

    func `[]`[T](s: ReservedMemSeq[T]; rpos: BackwardsIndex): lent T

  Source Edit

    func `[]`[T](s: var ReservedMemSeq[T]; rpos: BackwardsIndex): var T

  Source Edit

    func len[T](s: ReservedMemSeq[T]): int

  Source Edit

    func commitedLen[T](s: ReservedMemSeq[T]): int

  Source Edit

    func maxLen[T](s: ReservedMemSeq[T]): int

  Source Edit

# Templates

    template distance(lhs, rhs: pointer): int

  Source Edit

    template shift(p: pointer; distance: int): pointer

  Source Edit