PackedArray icon indicating copy to clipboard operation
PackedArray copied to clipboard

Support for more than 2^32 elements?

Open JustinChu opened this issue 7 years ago • 5 comments

It seems there is a limit to use a uint32_t for the count parameter of the PackedArray_create() function. Do you foresee any major issues modifying the code downstream to allow for a uint64_t count so I can populate it with more than 2^32 elements?

JustinChu avatar Apr 06 '18 03:04 JustinChu

Hello @JustinChu

I never needed more than UINT32_MAX elements. That's why I chose uint32_t instead of size_t. I also recall back then, Microsoft compiler didn't support %zu printf() format specifier and I would have had to use something like

#if defined(_MSCVER)
  #define SIZET_FMT "%Iu"
#elif defined(__GNUC__)
  #define SIZET_FMT "%zu"
#else
  #define SIZET_FMT "%u"
#endif

You should be just fine replacing uint32_t count with uint64_t count or size_t count. If you decide yo use size_t you need #include <stddef.h> in PackedArray.h. In any case you will need to fix -Wformat warnings on printf() calls when compiling the self test and the self bench programs with GCC or Clang.

That being said, at this point I'm undecided on whether it's a change I want to merge.

gpakosz avatar Apr 06 '18 06:04 gpakosz

My code only needs to work in a Linux environment using gcc and maybe clang. I'll give a shot and let you know if I have any problems.

Thanks.

JustinChu avatar Apr 06 '18 18:04 JustinChu

So far it seems to be okay. I basically changed a bunch of uint32_t to uint64_t https://github.com/JustinChu/PackedArray/commit/bdc91637edb210950a668f280fcabf7a5788cd57. I tested in a few informal cases with no problems so far. I have yet to touch the simd code, however.

Unrelated question (maybe I should add this to another issue). How thread safe is the code? I assume I won't be able to atomically insert values but are at least lookups safe?

Ideally, I would like to be able to do atomic inserts with compare_and_swap (e.g. with atomic built-ins like __sync_bool_compare_and_swap) operations but that doesn't seem like something easily done with a packed array. I wonder if it is possible to use an unaligned pointer in a compare and swap operation...

JustinChu avatar Apr 06 '18 23:04 JustinChu

did you ever get to modifying the SIMD code?

NickStrupat avatar Mar 11 '19 00:03 NickStrupat

I found that replacing all uint32_t with uint64_t in PackedArray.c and PackedArray.h got me the extra space I needed. Likely overkill but ensures I don't overflow some uint32_t I forgot about. Thanks for this libary gpakosz, super cool stuff!

guinn8 avatar Jan 13 '22 17:01 guinn8