~satchmo/libvmm#48: 
Rethink allocator design of FAM struct wrapper

#Pros/Cons

Currently, FamStruct allocates both header members and the flexible array member according to the polymorphic allocator passed in.

With this design, you get a few benefits:

  • A default behavior consistent with what C provides (i.e., the struct is allocated on the global heap).
  • A simple interface for custom allocation strategies due to the type erasure provided by polymorphic allocators.
  • FAM structs are commonly used for handling large amounts of data, which allocation is sort of for.

However, there are some downsides:

  • An extra pointer has to be stored for the allocator.
  • You have some overhead due to virtual calls for the polymorphic allocators.
  • Since all we're allocating is PODs, a major benefit of polymorphic allocators (that you can propagate them to inner elements) is never taken advantage of.
  • The size of the FAM has to be known at compile-time, which is different than what C does.
    • I'm not too sure though that the run-timeness of C's FAM structs is even used. I'll have to look around a bit on this one though.

#Notes

This isn't a proposal to revert back to stack-based FAM structs. For one thing, FAM structs are commonly used for large amounts of data, which the stack isn't designed for.

Status
REPORTED
Submitter
~satchmo
Assigned to
No-one
Submitted
3 years ago
Updated
3 years ago
Labels
Proposal