memset

sets a range of memory to a specific byte-value

Requires

#include "tiktag.h"

Definition

void* memset (void* ptr, unsigned char value, unsigned int size)

Description

The memset() function is used to set a block of memory to a particular value. It stands for "memory set" and is defined in the "tiktag.h" header file.

Parameters

void* ptr: A pointer to the start of the memory block to be set

unsigned char value: The value to be set (as an unsigned char value)

unsigned int size: The number of bytes to be set

Return Value

void*

Remarks

-

Example: allocate and set a block of memory

main.js:

import {_wasmInitA} from "./tt/ttWASM.js";
import wasm from "./web.wasm";

async function main()
{
	const wasmInstance = await _wasmInitA(wasm, {}, null);
	wasmInstance.exports.allocAndSetMem (100, 42);
}

main();

myCppExample.cpp:

#include "tiktag.h"

char* _buffer;

_export void allocAndSetMem (unsigned size, unsigned int val)
{
	_buffer = (char*) malloc (size);
	memset (_buffer, val, size);
	for (int i=0;i<size;i++)
		consoleNum ("Mem: ", _buffer[i]);
}

Output:

See Also

malloc