Good examples of value types
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 5 19:07:39 PDT 2015
On Tuesday, 5 May 2015 at 20:40:59 UTC, Luís Marques wrote:
> Hi,
>
> For a comparison with the Java language, I'm trying to come up
> with some good examples of custom types that should be value
> types (but that must be ref types in Java). I think the most
> obvious ones are numeric types. So BigNum, MyNum, etc. are good
> examples because programmers are used to numeric types being
> value types, and having them suddenly become a ref type just
> because it's MyNum instead of long is really annoying. Still,
> could you come up with some type that would really benefit from
> being a value type but that isn't numeric (or otherwise
> similar)?
>
> Thanks for your help!
>
> Luís
Let me tell you an actual war story of mine.
We have this program that is computationally intensive written in
java. Somewhere in the core of the program, we have a LRU cache,
with some entries sticking in there, and most entry getting
evicted soon enough (typical pareto kind of thing).
Problem is, all these entries needs to be value types (we are in
java) and, by the time things gets evicted from the LRU cache,
they have moved to the old generation.
The whole damn thing generate a ton of garbage.
The obvious solution is to use value types in the cache, but that
not possible. I won't go in the details, but that was a really
hard problem to solve, that kept us busy for for longer then it
should have because of language limitations.
Long story short: value types are useful.
More information about the Digitalmars-d
mailing list