Skip to content
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

MAINT: Allocate fewer bytes for empty arrays. #7820

Merged
merged 1 commit into from
Jul 11, 2016

Conversation

charris
Copy link
Member

@charris charris commented Jul 10, 2016

Currently the number of bytes allocated is the product of the non-zero
dimensions x element_size, which can create huge memory allocations for
empty arrays. Change that to just allocate enough for one element. Some
allocation is needed for the array.data attribute to work correctly.

Note: Could probably allocate a minimal number of bytes, say 16 as
dictated by alignment, but the old intended number is used here as a
more conservative fix.

Closes #7813.

Currently the number of bytes allocated is the product of the non-zero
dimensions x element_size, which can create huge memory allocations for
empty arrays. Change that to just allocate enough for one element. Some
allocation is needed for the array.data attribute to work correctly.

Note: Could probably allocate a minimal number of bytes, say 16 as
dictated by alignment, but the old intended number is used here as a
more conservative fix.

Closes numpy#7813.
@charris charris added this to the 1.11.2 release milestone Jul 10, 2016
@charris
Copy link
Member Author

charris commented Jul 10, 2016

This brings up the question if element size can ever be zero? I think we avoid that at present -- no S0 strings for instance -- but it might make sense to deal with the possibility up front.

@charris
Copy link
Member Author

charris commented Jul 11, 2016

Putting this in for backport to 1.11.x.

@charris charris merged commit 08fc49e into numpy:master Jul 11, 2016
@charris charris deleted the fix-empty-array-allocation-size branch July 11, 2016 15:43
@charris charris removed this from the 1.11.2 release milestone Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

numpy.zeros((0, 2**31-1)) crashes on 32 bit Python
1 participant