# FixTask Documentation

Back to summary

`import "task/heap";`

## Heap class

Heap allows to run FixScript code in separate context.

Table of contents:

- Initialization
- Garbage collection
- Execution time limit
- Reference handling in value handles
- Array access
- String access
- Hash access
- Native handles
- Weak references
- Error handling
- Value inspection
- Cloning & serialization
- Script loading & running

### Initialization

`static function create(): Heap`
`static function create_full(): Heap`
`function destroy()`

### Garbage collection

`function collect()`
`function get_size(): Integer`
`function adjust_size(relative_change: Integer)`
`function ref(value: Value)`
`function unref(value: Value)`

### Execution time limit

`function set_time_limit(limit: Integer)`
`function get_remaining_time(): Integer`
`function get_async(): AsyncHeap`

### Reference handling in value handles

`function mark_ref(value: Value)`

### Array access

`function create_array(len: Integer): Value`
`function set_array_length(array: Value, len: Integer)`
`function get_array_length(array: Value): Integer`
`function is_array(value: Value): Boolean`
`function set_array_elem(array: Value, idx: Integer, value: Value)`
`function get_array_elem(array: Value, idx: Integer): Value`
`function append_array_elem(array: Value, value: Value)`
`function get_array_range(array: Value, off: Integer, len: Integer, values: Value[], values_off: Integer)`
`function set_array_range(array: Value, off: Integer, len: Integer, values: Value[], values_off: Integer)`
`function get_array_values(array: Value, off: Integer, len: Integer, values, values_off: Integer)`
`function set_array_values(array: Value, off: Integer, len: Integer, values, values_off: Integer)`
`function get_array_numbers(array: Value, off: Integer, len: Integer, numbers, numbers_off: Integer)`
`function set_array_numbers(array: Value, off: Integer, len: Integer, numbers, numbers_off: Integer)`
`function copy_array(dest: Value, dest_off: Integer, src: Value, src_off: Integer, count: Integer)`

### String access

`function create_string(str: String): Value`
`function create_string(str: String, off: Integer, len: Integer): Value`
`function is_string(string: Value): Boolean`

### Hash access

`function create_hash(): Value`
`function is_hash(hash: Value): Boolean`
`function set_hash_elem(hash: Value, key: Value, value: Value)`
`function get_hash_elem(hash: Value, key: Value): Value`
`function remove_hash_elem(hash: Value, key: Value): Value`
`function clear_hash(hash: Value)`
`function get_hash_entry(hash: Value, idx: Integer)`

### Native handles

`function create_handle(handle: Handle): Value`
`function is_handle(value: Value): Boolean`
`function get_handle(value: Value): Handle`

### Weak references

`function create_weak_ref(value: Value): Value`
`function create_weak_ref(value: Value, container: Value): Value`
`function create_weak_ref(value: Value, container: Value, key: Value): Value`
`function get_weak_ref(weak_ref: Value): Value`
`function is_weak_ref(weak_ref: Value): Boolean`

### Error handling

`function create_error(string_or_value: Value): Value`
`function create_error_string(msg: String): Value`

### Value inspection

`function dump_value(value: Value)`
`function dump_value(value: Value, newlines: Boolean)`
`function to_string(value: Value): String`
`function to_string(value: Value, newlines: Boolean): String`

### Cloning & serialization

`function clone(value: Value): Value`
`function clone_deep(value: Value): Value`
`function clone_to(value: Dynamic): Value`
`function clone_to(value: Dynamic, resolve_existing: Boolean): Value`
`function clone_to(value: Dynamic, load_func, load_data): Value`
`function clone_from(value: Value): Dynamic`
`function clone_from(value: Value, resolve_existing: Boolean): Dynamic`
`function clone_between(other: Heap, value: Value): Value`
`function clone_between(other: Heap, value: Value, resolve_existing: Boolean): Value`
`function clone_between(other: Heap, value: Value, load_func, load_data): Value`
`function serialize(value: Value): Byte[]`
`function serialize(bytes: Byte[], value: Value): Byte[]`
`function unserialize(bytes: Byte[]): Value`
`function unserialize(bytes: Byte[], off: Integer, len: Integer): Value`
`function unserialize(bytes: Byte[], off_ref: Integer[]): Value`

### Script loading & running

`function load(script: String, src: String, load_func, load_data)`
`function load_script(script: String)`
`function reload(script: String, src: String, load_func, load_data)`
`function is_loaded(script: String): Boolean`
`function get_function(script: String, name: String): Value`
`function get_function_info(value: Value): FunctionInfo`
`function run(script: String, func_name: String, args: Value[]): Value[]`
`function call(func: Value, args: Value[]): Value[]`
`function register_native_function(name: String, func, data)`
`static function resolve_existing(data, heap: Heap, name: String)`