79498425

Date: 2025-03-10 15:17:48
Score: 0.5
Natty:
Report link

You would need to use a global because lwgeom_set_handlers belongs to the global context, i.e. it is not part of an object that can have it's own separate state.

Consider this workflow:

A:

  1. we decide to use pool_1 to allocate memory; this is SomeInfo pool_1

  2. call lwgeom_set_handlers to use allocator pointing to pool_1

  3. lwgeom now does a bunch of stuff and want to allocate 12 objects, it will call the allocator set above and 12 objects get allocated form pool_1

B:

  1. now we want to use pool_2

  2. call lwgeom_set_handlers to use allocator pointing to pool_2

  3. lwgeom need to allocate 4 objects and does that with above allocator from pool_2

Implementation:

A:

  1. assign active_pool = &pool_1;

  2. do stuff with lwgeom library that requires allocation

B:

  1. create pool_2 in case it was not created above

  2. assign active_pool = &pool_2;

  3. do stuff with lwgeom library that requires allocation

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: saintMath