JohnAD / decimal128

A Decimal128 IEEE 754 2008 number library for the Nim programming language.
MIT License
25 stars 2 forks source link

Thread safety #4

Open mratsim opened 4 years ago

mratsim commented 4 years ago

Just a quick reminder that it might be necessary to use this library in a multithreaded context for example for accounting software with work split across one core per year.

In that case trivial types like arrays should be preferred over sequences if possible, for example here: https://github.com/JohnAD/decimal128/blob/9ec5431b583cb22789ddf1c47dab22e99b1d74b5/src/decimal128/dpd.nim#L72-L127

This also avoids memory allocation which might be a bottleneck if done regularly and which is also problematic for long-running processes as it might lead to memory fragmentation.

JohnAD commented 4 years ago

I will put this on my list of improvements!

That particular reference, the contents of dpd.nim are not actually being used right now as the library does not support densley packed binary yet. decimal128.nim does not even import it. But when it does, I'll be sure to convert to a static array. The array is fixed at 34 bytes, so converting to a static array will be easy.