Skip to content

Conversation

eeeebbbbrrrr
Copy link

Perhaps this might could replace PgAllocator given more work.

The idea here was to come up with an API that's a little more natural to working with PG in C, as it relates (at least) to dealing with memory contexts.

In any given function exposed Rust function, it might look something like this:

{
   let PgMemoryContext cxt = PgMemoryContext::top_transaction().switch_to();  // switches to the TopTransactionContext
   let some_bytes = cxt.alloc(32768);
   some_bytes
   // cxt gets dropped and switches back automatically to whatever the CurrentMemoryContext was
}

Alternatively, you could just allocate some PG memory directly in a context:

{
   let some_bytes = PgMemoryContext::current_transaction().alloc(32768);
   some_bytes
}

None of this is related to how Rust allocates memory, of course. Rusts normal rules for its allocated bytes would apply. I haven't really yet through through how to reassign ownership of Rust allocated memory to a particular Postgres MemoryContext, but I'm not sure that's even a useful thing -- any memory we want PG to hold on to needs to be allocated by PG anyways.

…his might could replace PgAlocator given more work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant