← All posts

Why Does Ambiorix Build Its Own “Container”?

Grow through practice

No need to finish reading — test now

This is the opening post of the series. Note: it is based on reading the open-source Ambiorix code and my own understanding; the “motivation” part is inference, not an official statement.

First, what does “container” mean?

“Container” has two meanings, and they are easy to mix up:

What it isIn AMX
Data containerlist/string/hash/variant — holds datalibamxc (the foundation)
Object containercomponent registration, lifecycle, dependency lookup and assembly (the spirit of Spring IoC)libamxrt + libamxd + libamxb

This post is about the latter. list/string is not the subject of “rewriting a set”; it is simply the foundation the object container needs along the way.

What is an object container?

In Spring, you write beans, and the container creates them, injects dependencies, and manages their lifecycle.

AMX does the same kind of thing in C:

  • How components register (entry point);
  • Lifecycle: init → start → stop (libamxrt);
  • How dependencies are found: no mutual #include; they look up and call each other through the bus (libamxb);
  • How state is described: objects/parameters/functions (libamxd, the data model).

In one sentence: it does not manage “where data lives”; it manages “how components live and how they connect”.

One nuance: Spring's core is injection (the container hands dependencies to you); AMX's core is lookup + assembly (components find each other through the bus/path, ODL assembles the object tree, and libamxrt manages the lifecycle). Same spirit, different mechanism: AMX is not a pure DI framework.

Spring core vs AMX

Spring coreAMX equivalentNotes
IoC container (create/wire beans)libamxrt + libamxoruntime + ODL assembly
Bean / propertyObject / Parameter (libamxd)data model
Dependency injection (constructor/field)bus/path lookup (libamxb)lookup, not injection
Lifecycle (init / destroy)init / start / stopcloser to a “service lifecycle”
Scope (singleton / prototype)singleton / multi-instance tablesimilar concept
AOPevents / actions / ACLsimilar capability, but not AOP

Why it had to build one

1) C has no Spring

C has no IoC container, no dependency injection, no unified component lifecycle. Either every project writes its own “init order + global variables + callback registration”, or you build a container. AMX chose the latter.

2) Buses are fragmented

In the embedded world: ubus (OpenWrt), D-Bus (RDK-B/desktop), plus private buses.

Using one bus's API directly locks you to that platform. AMX's approach: put a unified C API on top of the bus (libamxb), so changing the bus does not change business code.

3) Components need a “describable state”

If components are coupled through #include and direct function calls, the system becomes harder and harder to change. AMX exposes components through a data model (objects/parameters/functions + paths):

  • what each component can do is written on the object tree;
  • assembly is done with ODL, not hard-coded;
  • clients access by path and do not care where the implementation lives.

4) It must be “serializable” (the watershed between it and an ordinary framework)

Objects, parameters, RPC arguments — all must be encoded/decoded. amxc_var_t (Variant) can hold int/string/bool/list/hash; containers + Variant form a dumpable tree: → ODL assembly / RPC / data model all rely on it.

GLib/STL cannot provide this combination of “object container + data model + serialization”.

5) Embedded and long-term maintenance

  • Pure C, as few dependencies as possible beyond libc (libamxc.so is about 187K after strip);
  • intrusive containers, zero allocation, predictable;
  • its own stack and its own versioning, not held hostage by an external project;
  • BSD-2-Clause-Patent, commercial-friendly;
  • carrier-grade requirements: ACL, transactions, events, lifecycle.

Then why write list/string too?

Because they are the foundation of that object container:

  • the data model needs dynamic strings (paths, keys, text);
  • the object tree/instances/Variant need linked lists and hashes;
  • C has no standard containers, and GLib is too heavy.

But they are a side effect, not the goal. The goal has always been that object container.

One sentence

What it builds is not “a list/string library”, but “an object container in C” — components, lifecycle, bus, data model. Once you understand this, libamxc/libamxd/libamxb each fall into place.


Next: “I Searched for a C ‘Container’ for Years, Until I Met Ambiorix” — my journey.

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.