-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use size_t for sequence sizes #1943
Comments
Isn't the purpose of size_t to provide a reasonable size measurement type adapted to each platform? That means size_t is highly platform dependent as far as I can see, and we've tried to avoid such C types elsewhere in favor of explicit bit widths in order to get a consistent behavior across all targets. So I don't know. I can see the merit of using size_t internally since that's the type used by many C library functions, but the type we choose will nevertheless have to relate to the Acton type that len() returns. And that type ought have a platform-independent bit width, I think. |
But if the question is just size_t versus int, I'm all in favor of size_t. Though picking a fixed bit width type has additional merits, as it were. |
@nordlander Right, so since |
Yep, that summarizes it well. And the casting that must remain isn't just a nuisance, it actually represents our responsibility to correctly map Acton sizes (as represented by an uint64_t, say) to whatever size_t means on each particular platform. And vice versa, of course. |
I don't have more to add; at some point we should go through everything and replace all int types with explicitly sized types, but size_t is probably an improvement for now. A minor thing is that it disturbs me a little to use a 64 bit field to hold e.g. the length of a list. A 32 bit field is enough for lists of four billion elements, but I will not fight for it, since it is probably a disturbance due to starting as a programmer in the late sixties... |
Proposal
The sizes and capacities of sequences like
list
,str
,bytes
, etc. are mostly implemented in C with typeint
. It would be better if possible to usesize_t
for such object size quantities.Motivation
Use of
size_t
for sequence sizes would make interoperation with established C libraries more natural and avoid artificially limiting sequence sizes with a signed type that may be smaller than the real maximum supported by memory.Alternatives
Casting to
size_t
when integrating with C libraries that expect it does work to an extent but has the limitations described above.The text was updated successfully, but these errors were encountered: