Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inaccel/numpy-allocator
Configurable memory allocations
https://github.com/inaccel/numpy-allocator
numpy python
Last synced: about 13 hours ago
JSON representation
Configurable memory allocations
- Host: GitHub
- URL: https://github.com/inaccel/numpy-allocator
- Owner: inaccel
- License: apache-2.0
- Created: 2021-03-30T11:08:27.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-07T08:07:36.000Z (3 months ago)
- Last Synced: 2024-12-15T04:35:38.596Z (about 1 month ago)
- Topics: numpy, python
- Language: C
- Homepage:
- Size: 47.9 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Memory management in [NumPy](https://numpy.org)*
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/inaccel/numpy-allocator/master?labpath=NumPy-Allocator.ipynb)
[![PyPI version](https://badge.fury.io/py/numpy-allocator.svg)](https://badge.fury.io/py/numpy-allocator)**NumPy is a trademark owned by [NumFOCUS](https://numfocus.org).*
#### Customize Memory Allocators
Α metaclass is used to override the internal data memory routines. The metaclass has four optional fields:
```python
>>> import ctypes
>>> import ctypes.util
>>> import numpy_allocator
>>> my = ctypes.CDLL(ctypes.util.find_library('my'))
>>> class my_allocator(metaclass=numpy_allocator.type):
... _calloc_ = ctypes.addressof(my.calloc_func)
... _free_ = ctypes.addressof(my.free_func)
... _malloc_ = ctypes.addressof(my.malloc_func)
... _realloc_ = ctypes.addressof(my.realloc_func)
...
```#### An example using the allocator
```python
>>> import numpy as np
>>> with my_allocator:
... a = np.array([1, 2, 3])
...
>>> my_allocator.handles(a)
True
```