Implementation:Google deepmind Mujoco mj makeData
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, Memory_Management |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
Concrete tool for allocating and initializing MuJoCo simulation state provided by the MuJoCo C API.
Description
The mj_makeData function allocates an mjData structure sized according to the given model, initializes plugins, and resets all state fields to the model's default configuration. The allocated structure uses arena-based memory management for efficient temporary allocation during simulation steps.
Usage
Call this function once per simulation thread after loading the model. The returned mjData pointer is the mutable workspace for all simulation computations.
Code Reference
Source Location
- Repository: mujoco
- File: src/engine/engine_io.c
- Lines: 1100-1108
Signature
mjData* mj_makeData(const mjModel* m);
Import
#include <mujoco/mujoco.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Compiled model that determines allocation sizes |
Outputs
| Name | Type | Description |
|---|---|---|
| return | mjData* | Allocated and initialized simulation state (NULL on failure) |
Usage Examples
#include <mujoco/mujoco.h>
// Load model
char error[1000];
mjModel* m = mj_loadXML("humanoid.xml", NULL, error, 1000);
// Allocate simulation state
mjData* d = mj_makeData(m);
// Simulation loop
for (int i = 0; i < 1000; i++) {
mj_step(m, d);
}
// Cleanup
mj_deleteData(d);
mj_deleteModel(m);