Memory model #3
Replies: 9 comments 18 replies
|
Things to consider while choosing the memory model,
Memory model to discuss, |
|
@vasucp1207 we have put unsafe in our grammar, so we could use some boundary of safe and unsafe to design around or we can consider removing unsafe too if need arises? |
Generational ReferencesFor Bedrock, we want deterministic performance, and the runtime should be lightweight and easy to implement. The best approach that I can think of is a Hybrid Generational Memory Model (inspired by By extending generation tracking to stack frames alongside heap allocations, both safe and unsafe code stay clean and well-defined. so we can provide safety in both stack and heap.
|
Tracing GCThis is traditional tracing GC memory model. User will allocate data on heap using GC will allow multiple references without enforcing any ownership model. The data remain alive as long as it is reachable through GC tracing. The benefit of this model is its very simplicity and the grammer will remains relatively clean just a couple of new addition of keywords like |
Region based memory modelThis model uses The compiler tracks the lifetime of references to make sure that a reference cannot outlive the region it currently lives in. The compiler can determine that lifetime of Here the value will be copied or moved outside the region. |
|
@vasucp1207 \How |
|
@vasucp1207 could you give the document for the region based memory model you were talking about, I wanna know how it will work. |
Arena Region memory modelThe memory model is based on regions(arenas). Every allocation belongs to exactly one region, and the region determines when that allocation is reclaimed. Invariants about region model
Lifetimes conceptsLexical regionA lexical region corresponds to a local scope. Here both See the same example without implicit region blocks Function paramsParameters are not a separate storage region. A reference parameter borrows an allocation from the caller. Because friend might have a shorter lifetime than p, we need some lifetime annotation hints here. ReturnA function cannot return a reference to storage whose lifetime ends before the caller can use the return value. Static regionStatic storage lives for the entire program. TODOS
|
|
Also, @vasucp1207 we need to define how memory managed by the regions interacts with unsafe blocks. For eample: |
Uh oh!
There was an error while loading. Please reload this page.
Thread to discuss about different memory models
All reactions