libriscv/rvscript

Sharing objects with VMs

Opened this issue · 2 comments

Object sharing is the current topic of research right now. It's fairly OK to share plain-old-data, but it would be nice if it could be more dynamic somehow.

	struct GameObject objects[200]; // Page worth of objects

	/* Insert objects into memory.
	   This allows zero-copy sharing of game state. */
	static constexpr Script::gaddr_t OBJECT_AREA = 0xC000000;
	gameplay.machine().memory.insert_non_owned_memory(
		OBJECT_AREA, objects, sizeof(objects) & ~4095UL);

This is the current way of doing things.
We can now access the objects in the VMs, and if we use the same inline code interface the output should be the same.

One idea here is to use the heap allocator to guarantee the object doesn't cross a page. If that were added, we could allocate and emplace objects at-will.

One idea here is to use the heap allocator to guarantee the object doesn't cross a page. If that were added, we could allocate and emplace objects at-will.

I've implemented this and it seems to work well. No real performance penalty other than a possible double-chunk split in order to handle page boundaries. Now I am wondering if there are other places that could benefit from this.