Skip to main content

memorymanagement

Provides memory management support.

The only Python implementation currently supported is the one made by the CPython team. The rest remain untested.

Table of Contents

Modules

cleaning

Provides the class Cleaner, which allows you to flag references stored in memory to eventually erase them. It is also possible to modify the list of flagged references through its methods.

pointers

Provides a safe implementation of pointers for Python.

Class Pointer

The pointer itself. Imitates the behaviour of C pointers. Pointer points to a reference, not to an object stored in memory.

Decorator pointerize

Allows functions to receive pointers instead of values.

Installation

You can install the memorymanagement package from PyPI as follows:

pip install memorymanagement

Usage

Class Cleaner

# Imports
# Make your imports here
from memorymanagement import Cleaner # Importing class Cleaner

Right after imports are done, I recommend to initialize an instance of class Cleaner, so no arguments are needed. This is the optimal use this class was designed for.

# Initialize cleaner object
cleaner=Cleaner()

Create, for example, these variables (can be global or local):

value_1=10
value_2=50
value_3=100

Update the list of flagged references like one of the following:

  • Including all new variables:

    cleaner.update()
    print(cleaner.flagged)
    

    Output:

    ["value_1","value_2","value_3"]
    
  • Excluding some variables:

    cleaner.update(exclude="value_2")
    print(cleaner.flagged)
    

    Output:

    ["value_1","value_3"]
    

    cleaner.update(exclude=["value_2","value_3"])
    print(cleaner.flagged)
    

    Output:

    ["value_1"]
    
  • Include again some variables:

    After having excluded some variables

    cleaner.update(exclude=["value_2","value_3"])
    

    You can reintroduce them

    # Create a new variable and update
    value_4=150
    cleaner.update(exclude="value_4",include="value_2") # "include" can also be a list of strings
    print(cleaner.flagged)
    

    Output:

    ["value_1","value_2"]
    

You can also directly include or exclude references like so:

cleaner.exclude(<name_var_1>,<name_var_2>,...)
cleaner.include(<name_var_1>,<name_var_2>,...)

To flag all the excluded variables at once, you can use:

cleaner.include_all(exclude=[<var_1>,<var_2>,...]) # exclude: optional keyword argument, accepts strings and iterables of strings

You can also exclude all the flagged variables like so:

cleaner.exclude_all(include=[<var_1>,<var_2>,...]) # include: optional keyword argument, accepts strings and iterables of strings

And reset the cleaner's parameters like so:

cleaner.purge()

Class Pointer

Example:

# Import the `Pointer` class
from memorymanagement import Pointer
# Create a pointer to a variable
p=Pointer(x:=10).select_ref() # So it points to "x" reference, instead of every reference. Also `p=Pointer(x:=10,"x")`
# Print variable and pointer's value
print(f"x:\n{x}\n\nPointer:\n{p.value}\n\n")
# Set variable to 20
x=20
# Print variable and pointer's value
print(f"x:\n{x}\n\nPointer:\n{p.value}\n\n")
# Set variable to 10
x=10
# Set pointer's value to 20
p.value=20
# Print variable and pointer's value
print(f"x:\n{x}\n\nPointer:\n{p.value}")

Output:

x:
10

Pointer:
10


x:
20

Pointer:
20


x:
20

Pointer:
20

Decorator pointerize

Example:

# Import pointerize decorator
from memorymanagement import pointerize
# Define and decorate `myFunction`
@pointerize
def myFunction(value:int):
    # Set the value to 20
    value=20
# Set a new variable to a value (10 in this case)
x=10
# Print variable
print(f"Value: {x}")
# Execute the function using a pointer to `x`
myFunction(Pointer(x))
# Print `x` variable
print(f"Value: {x}")

Output:

Value: 10
Value: 20

Contribution

To contribute to this project fork this repository and clone your fork. Pull requests will be revised by the owner before being accepted or rejected.

There are two branches:

  • PyPI: the main branch, for releases.
  • TestPyPI: for pre-releases or development versions.

Pull requests from TestPyPI to PyPI will only be done by the owner when a new release is ready.

Branch merging

To merge branches properly with PyPI branch in your cloned repository, you will need to have the .gitattributes file in the PyPI branch and execute the following commands, while in repo directory, in your PowerShell:

git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"

This way, README.md and setup.cfg files will not be overwritten in the PyPI branch.

Metadata

Release files for memorymanagement 1.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memorymanagement 1.11.1
File Size Uploaded Provenance Actions
memorymanagement-1.11.1.tar.gz 19.2 kB Without provenance Details for memorymanagement-1.11.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for memorymanagement 1.11.1
File Interpreter ABI Platform Actions
memorymanagement-1.11.1-py3-none-any.whl Python 3 none any Details for memorymanagement-1.11.1-py3-none-any.whl

Total release size: 39.0 kB

Release files / memorymanagement-1.11.1.tar.gz

Download URL memorymanagement-1.11.1.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
290b0554df5f7bd924d870091c32a4f5d04af7dc5106b98be1cff756730cd5d9
BLAKE2b-256 checksum
How to use checksums
0f0f661838bd6ccac2d7902eb3a97cdd587877b640a61a39251934768dfd7270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / memorymanagement-1.11.1-py3-none-any.whl

Download URL memorymanagement-1.11.1-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a238754ea6d5470b779ec5b104244acc91b9016ab5554489b993ed286da621d9
BLAKE2b-256 checksum
How to use checksums
cdc86ca0d356af5f9fcaa4cf4bb114bfaf6772e033f90539d1c8451e8177ca41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for memorymanagement 1.11.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.11.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page