Author Topic: Allocators and context  (Read 7511 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Allocators and context
« on: October 19, 2018, 02:19:33 PM »
As is possibly well known, Jai uses a "context" that can be pushed / popped.

If the standard malloc and libraries then uses the context we gain some very powerful abilities.

For example, consider handling a web request (I'm going to use C syntax here)

Code: [Select]
int process_request(Request *request)
{ ... }

int handle_request(Request *request)
{
    ....
    Context *context = push_context();
    BumpAllocator allocator = BumpAllocator.create(MAX_MEM);
    context.allocator = allocator;
    int err = process_request(request);
    pop_context();
    allocator.release();
    return err;
}

That is we emulate the php memory allocator. :D