Source Edit

Authors:Zahary Karadjov

This module provides utilities for reserving 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

oserrors, winlean, win_getsysteminfo

Types

  1. MemAccessFlags = int

Source Edit

  1. ReservedMem = object

Source Edit

  1. ReservedMemSeq[T] = object

Source Edit

Consts

  1. memExec = 16

Source Edit

  1. memExecRead = 32

Source Edit

  1. memExecReadWrite = 64

Source Edit

  1. memRead = 2

Source Edit

  1. memReadWrite = 4

Source Edit

Procs

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

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

Source Edit

Templates

  1. template distance(lhs, rhs: pointer): int

Source Edit

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

Source Edit