| Crates.io | memkit-bevy |
| lib.rs | memkit-bevy |
| version | 0.1.0-alpha.1 |
| created_at | 2025-12-27 00:40:37.601121+00 |
| updated_at | 2025-12-27 00:40:37.601121+00 |
| description | Bevy ECS integration for memkit |
| homepage | |
| repository | https://github.com/YelenaTor/memkit |
| max_upload_size | |
| id | 2006496 |
| size | 58,225 |
Bevy ECS integration for the memkit ecosystem.
Version: 0.1.0-alpha.1
memkit-bevy provides seamless integration between memkit and the Bevy game engine. It automatically manages frame lifecycle and exposes the allocator as a Bevy resource.
First/Last schedulesMkAllocatorRes as a Bevy ResourceMkSystemSet::FrameBegin and MkSystemSet::FrameEnd for orderingbevy_prelude feature for full Bevy re-exportsuse bevy::prelude::*;
use memkit_bevy::{MkPlugin, MkAllocatorRes};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(MkPlugin::default())
.add_systems(Update, my_system)
.run();
}
fn my_system(alloc: Res<MkAllocatorRes>) {
// Frame automatically managed by plugin
// Allocations are valid until end of frame
if let Some(data) = alloc.frame_box(MyData::new()) {
// ... use data ...
}
}
#[derive(Default)]
struct MyData {
value: f32,
}
use memkit::MkConfig;
use memkit_bevy::MkPlugin;
// Option 1: Custom config
let config = MkConfig {
frame_arena_size: 32 * 1024 * 1024, // 32 MB
..Default::default()
};
App::new()
.add_plugins(MkPlugin::with_config(config))
.run();
// Option 2: Just set arena size
App::new()
.add_plugins(MkPlugin::with_arena_size(64 * 1024 * 1024)) // 64 MB
.run();
memkit-bevy provides system sets for proper ordering:
use memkit_bevy::{MkPlugin, MkSystemSet};
App::new()
.add_plugins(MkPlugin::default())
// Run after frame begins
.add_systems(First, my_init_system.after(MkSystemSet::FrameBegin))
// Run before frame ends
.add_systems(Last, my_cleanup_system.before(MkSystemSet::FrameEnd))
.run();
fn my_system(alloc: Res<MkAllocatorRes>) {
// Raw pointer allocation (you must initialize)
let ptr: *mut MyStruct = alloc.frame_alloc::<MyStruct>();
// Boxed allocation (initialized)
let boxed: Option<MkFrameBox<MyStruct>> = alloc.frame_box(MyStruct::default());
// Slice allocation
let slice: Option<MkFrameSlice<f32>> = alloc.frame_slice::<f32>(1024);
// Check if frame is active
if alloc.is_frame_active() {
// Safe to allocate
}
}
| Feature | Description |
|---|---|
bevy_prelude |
Re-exports bevy::prelude::* for convenience |
| Type | Description |
|---|---|
MkPlugin |
Bevy plugin for memkit integration |
MkAllocatorRes |
Bevy resource wrapping MkAllocator |
MkSystemSet |
System sets for frame lifecycle ordering |
| memkit-bevy | Bevy |
|---|---|
| 0.12.x | 0.17.x |
First schedule): Calls MkAllocator::begin_frame()Update, etc.): Use Res<MkAllocatorRes> for frame allocationsLast schedule): Calls MkAllocator::end_frame(), resetting the arenaAll frame allocations are automatically freed when the frame ends — no manual cleanup needed.
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE.md file for details.