java-merge-sort icon indicating copy to clipboard operation
java-merge-sort copied to clipboard

Add helper methods for calculating approximate object mem usage

Open cowtowncoder opened this issue 14 years ago • 1 comments

Currently there is no support for estimating sortable entry lengths. It would be nice to have helper object to use for calculating object sizes: this can use conservative estimates, like:

  • Each object has some base per-instance overhead (say, 16 bytes)
  • Arrays also have base overhead (possibly less than Objects, but let's say 16 bytes) -- but also per-entry overhead (4 or 8 byte per reference type, 1/2/4/8 bytes for primitives)
  • Fields and array entries could perhaps be combined

We should probably have separate instances for 32-/64-bit machines; but can let caller specify which one is wanted.

Since this object is performance sensitive will probably need to keep it stateless (i.e. caller must pass all data as arguments), instead of using builder-style (which otherwise would be nice).

cowtowncoder avatar Dec 11 '11 04:12 cowtowncoder

Interesting reading: http://www.javamex.com/tutorials/memory/object_memory_usage.shtml

cowtowncoder avatar Dec 11 '11 04:12 cowtowncoder