ContiguousBlock:
Filter:
Classes | Control

ContiguousBlock : Object

Represents a range of integer addresses
Source: Engine.sc

Description

A ContiguousBlock is a range of addresses (generally integers >= 0) used in a ContiguousBlockAllocator. ContiguousBlockAllocator is used in Server to manage buffer numbers and audio/control bus indices.

ContiguousBlock(10, 2) spans address indices 10 and 11.

Additionally, a ContiguousBlock may be marked as in use or free. See -used.

Class Methods

ContiguousBlock.new(start, size)

Returns a new instance.

Arguments:

start

The starting address of the block.

size

The number of addresses after start to cover. Should be at least 1.

Inherited class methods

Instance Methods

.start

The starting address of the block.

.size

The number of addresses covered in the block.

.address

A synonym for start.

Returns:

The starting address of the block.

.lastAddress

The last address covered within this block: ContiguousBlock(10, 2).lastAddress returns 11.

.nextAddress

The starting address immediately following this block. ContiguousBlock(10, 2).lastAddress returns 12, because an adjoining block following this block must begin at address 12.

.used

.used = value

Boolean. true indicates that the block is in use, and false that it is available.

.adjoins(block)

Answers true if this block touches or overlaps with the argument, and false if there is a gap between the two blocks.

Arguments:

block

A second ContiguousBlock.

Returns:

Boolean.

Operations

.join(block)

Given two adjoining blocks, combines them into a single block. If the blocks do not adjoin, the result is nil.

Arguments:

block

A second ContiguousBlock.

Returns:

A new ContiguousBlock, spanning the full range of both input blocks.

.split(span)

Divides a ContiguousBlock into two new blocks.

Arguments:

span

The size of the first new block. The remainder of the receiver block's size will be allocated to the second block.

Returns:

There are three return cases:

Receiver's size > span
Returns an array of two ContiguousBlocks, partitioning the original address space.
Receiver's size == span
Returns an array with the original (identical) block and nil for the second partition.
Receiver's size < span
Returns nil, because the original address space cannot be partitioned to be larger than itself.

Inherited instance methods

Examples