sim

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package sim simulates client application working with the heap using malloc(3) API: malloc() and free().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpFunc

type OpFunc func(int) operation

OpFunc generates a malloc or free operations. The meaning of the integer parameter depends on the operation being generated: malloc(n) means generate a malloc operation to allocated n-bytes, free(n) means generate a free operation to release n-th allocation available at the moment of running the free operation.

type Option

type Option func(*Simulator)

Option modifies simulator configuration in some way, e.g., set manual operations.

func WithOps

func WithOps(ops []string) Option

WithOps configures simulator to replay operations.

type Simulator

type Simulator struct {
	// contains filtered or unexported fields
}

Simulator runs malloc operations on the heap. The operation can be random:

s := sim.NewSimulator(h, num)

or manually set:

s := sim.NewSimulator(h, 0, sim.WithOps([]string{"+10"})

func NewSimulator

func NewSimulator(h *heap.Heap, num int, opts ...Option) *Simulator

NewSimulator creates a heap simulator to generate num random operations. Use WithOps to override random operations with a list of manual operation in the form "op,op,..." where "op" is either "+N" to allocate a block of size N or "-N" to free N-th currently available allocation.

func (*Simulator) Allocated

func (sim *Simulator) Allocated() []int

Allocated returns a slice of allocated addresses.

func (*Simulator) Next

func (sim *Simulator) Next() bool

Next generates [simulator.numToGen] random operations, one at a time. It returns true if the operation was generated, else false.

func (*Simulator) Op

func (sim *Simulator) Op() operation

Op returns the last generated operation in Next().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL