Temporarily allocate *nbytes* from the given *pool*.
(pool, nbytes)
| 45 | |
| 46 | @contextlib.contextmanager |
| 47 | def allocate_bytes(pool, nbytes): |
| 48 | """ |
| 49 | Temporarily allocate *nbytes* from the given *pool*. |
| 50 | """ |
| 51 | arr = pa.array([b"x" * nbytes], type=pa.binary(), memory_pool=pool) |
| 52 | # Fetch the values buffer from the varbinary array and release the rest, |
| 53 | # to get the desired allocation amount |
| 54 | buf = arr.buffers()[2] |
| 55 | arr = None |
| 56 | assert len(buf) == nbytes |
| 57 | try: |
| 58 | yield |
| 59 | finally: |
| 60 | buf = None |
| 61 | |
| 62 | |
| 63 | def check_allocated_bytes(pool): |
no test coverage detected