wolfgangj / bone-lisp

The Bone Lisp programming language
Other
321 stars 21 forks source link

What lessons did you learn about mem mgmt model? #25

Open xphung opened 4 years ago

xphung commented 4 years ago

Hi, the semi-manual memory management used in Bone Lisp is of interest to me.

I'm looking at extending the S-expression syntax of WebAssembly into a full blown Lisp-like programming language. (Macros can then be used to the transform syntax of other languages into WebAssembly, effectively becoming a compiler platform).

WebAssembly doesn't have garbage collection (so the Bone Lisp model will fits in well). Can I ask what were the main lessons you learned in your experimentation with the Bone Lisp, and what would you do differently if you were designing a similar mem mgmt model today?

wolfgangj commented 4 years ago

You should definitely come up with a good solution to global state if you want to go full region-based. That might get a bit tricky if you want to be both fast and memory-safe.

Also, in Bone Lisp the regions are made of small blocks, which is unfortunate if you want to have e.g. large arrays. Today I would rather use two large sections of memory used for allocating (by simply bumping a pointer forward). Starting a new region would always switch to the other section.

Why we need two? Because we want to copy back the return value to the end of the previous region when we're leaving a region.