Skip to main content

Library to handle sparse bytes within a virtual memory space

Project description

Library to handle sparse bytes within a virtual memory space.

  • Free software: BSD 2-Clause License

Objectives

This library aims to provide utilities to work with a virtual memory, which constsis in a virtual addressing space where sparse chunks of data can be stored.

In order to be easy to use, its interface should be close to that of a bytearray, which is the closest pythonic way to store dynamic data. The main downside of a bytearray is that it requires a contiguous data allocation starting from address 0. This is not good when sparse data have to be stored, such as when emulating the addressing space of a generic microcontroller.

The main idea is to provide a bytearray-like class with the possibility to internally hold the sparse blocks of data. A block is ideally a tuple (start, data) where start is the start address and data is the container of data items (e.g. bytearray). The length of the block is len(data). Those blocks are usually not overlapping nor contiguous, and sorted by start address.

Python implementation

This library is the Cython complement to the Python implementation provided by the bytesparse Python package. Please refer to its own documentation for more details.

Cython implementation

The library provides an experimental Cython implementation. It tries to mimic the same algorithms of the Python implementation, while exploiting the speedup of compiled C code.

Beware that the Cython implementation is meant to be potentially faster than the pure Python one, but there might be even faster ad-hoc implementations of virtual memory highly optimized for the underlying hardware.

The addressing space is limited to that of an uint_fast64_t (typically 32-bit or 64-bit as per the hosting machine), so it is not possible to have an infinite addressing space, nor negative addresses. To keep the implementation code simple enough, the highest address (e.g. 0xFFFFFFFF on a 32-bit machine) is reserved.

Block data chunks cannot be greater than the maximum ssize_t value (typically half of the addressing space).

The Cython implementation is optional, and potentially useful only when the Python implementation seems too slow for the user’s algorithms, within the limits stated above.

If in doubt about using the Cython implementation, just stick with the Python one, which is much easier to integrate and debug.

More details can be found within cbytesparse.c.

Documentation

For the full documentation, please refer to:

https://cbytesparse.readthedocs.io/

Installation

From PyPI (might not be the latest version found on github):

$ pip install cbytesparse

From the source code root directory:

$ pip install .

Development

To run the all the tests:

$ pip install tox
$ tox

To regenerate the Cython files manually, run the following commands:

$ python scripts/cython_build_src.py
$ python scripts/cython_build_tests.py

or alternatively:

$ tox -e cythonize

Changelog

0.0.4 (2022-01-09)

  • Following the bytesparse Python package, version 0.0.4.

  • Refactored current implementation as the c sub-module.

  • Removed experimental backup feature.

  • Added dedicated methods to backup/restore mutated state.

  • Fixed some write/insert bugs.

  • Fixed some trim/bound bugs.

  • Methods sorted by name.

  • Removed useless functions.

0.0.2 (2022-01-03)

  • Forced extension compilation.

  • Using explicit factory methods instead of constructor arguments.

  • Added block collapsing helper function.

  • Minor fixes.

  • Improved test suite.

0.0.1 (2021-12-27)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cbytesparse-0.0.4.tar.gz (1.3 MB view details)

Uploaded Source

File details

Details for the file cbytesparse-0.0.4.tar.gz.

File metadata

  • Download URL: cbytesparse-0.0.4.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for cbytesparse-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d756356ad61871848499b3df4b907074d31130c7f589f6ad3852987200a702cd
MD5 9df67b9d312af32bd31c30e52b14093d
BLAKE2b-256 0307c3359c6afb235075ebe80c420c34bf735ae95dd1914f3b702c27c8c03406

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page