News for hackers. Stuff that matters.
Re:Could ImGUI Be the Future of GUIs? by loup-vaillant on Sunday April 28, 2019 @04:18AM (#19769986)
Arenas are the simplest allocation scheme ever.

  // Start of frame
  void *arena    = malloc(LOTS_OF_MEMORY);
  void *next_ptr = arena;

  // Allocate something
  object   = *next_ptr;               // return that value
  next_ptr = object_size + alignment; // crash if out of memory
 
  // End of frame
  free(arena);
By the way, such "separate complex ad hoc" memory allocation schemes are the reason why manual memory management is faster than garbage collection. If you did everything with malloc(), it would be slower (unless the GC language allocates much more than C, which they often do).
Re:Could ImGUI Be the Future of GUIs? by Keyframe on Sunday April 28, 2019 @06:49AM (#19770412)
No need to malloc each frame. Malloc at startup and memset each frame (don't even need to do that, tbh).
Re:Could ImGUI Be the Future of GUIs? by maccard on Sunday April 28, 2019 @07:31AM (#19770542)
Nope, just set the pointer back to where it started from. You do need to be super careful doing this though, as anything that relies on RAII (in c++ land) will be busted. You could manually call the destructor on the object in that case, but kind of defeats the purpose of the "no allocation" goals
Re:Could ImGUI Be the Future of GUIs? by geezerjay on Monday April 29, 2019 @01:59AM (#19776160)
C++ includes it's "placement new" feature specifically to cater to the memory pool needs. There's no allocation, and only constructor and destructor calls.
Re:Could ImGUI Be the Future of GUIs? by tom_ on Sunday April 28, 2019 @08:02AM (#19770645)
It’s a good idea to have a mode that does malloc every frame, as that makes stale pointers much easier to find.