Skip to main content

Adds support for memory management

Project description

memorymanagement

Provides memory management support.

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

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

How to use

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 global variables:

value_1=10
value_2=50
value_3=100

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

  • Including all new global 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>,...)

Class Pointer

Example:

from memorymanagement import Pointer
a=10
x=Pointer(a)
print(f"a:\n{a}\n\nPointer:\n{x.value}\n\n")
a=20
print(f"a:\n{a}\n\nPointer:\n{x.value}\n\n")
a=10
x.value=20
print(f"a:\n{a}\n\nPointer:\n{x.value}")

Output:

a:
10

Pointer:
10


a:
20

Pointer:
20


a:
20

Pointer:
20

Decorator pointerize

Example:

from memorymanagement import pointerize
@pointerize
def myFunction(value:int):
    value=20
    return
a=10
print(f"Value: {a}")
myFunction(Pointer(a))
print(f"Value: {a}")

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.

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'"

Or in your git bash terminal:

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, READMEs and setup files will not be overwritten in the PyPI branch.

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

memorymanagement-1.1.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memorymanagement-1.1.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file memorymanagement-1.1.3.tar.gz.

File metadata

  • Download URL: memorymanagement-1.1.3.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for memorymanagement-1.1.3.tar.gz
Algorithm Hash digest
SHA256 5bf37cea33c95888cce83d1f669b5ec458e3c434c13ef7b4a140260aafac1399
MD5 1dd8bd3166b30a27f9f9b6dfa144fb4a
BLAKE2b-256 7253b1404e7cfe8c6aa39b8379d20cf95b577e605a2fa42a344e35df613af2a6

See more details on using hashes here.

File details

Details for the file memorymanagement-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for memorymanagement-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6d333d943805fd854cbd9fd811fbe991dce14ed5790389b615ba2ed4fde13395
MD5 4b2105be8ade479dfda8cf82f3b3800b
BLAKE2b-256 2f6297c0b60ba7aba657b2f7b272cedd6016c4bdee77b09dad5c7f066da7303a

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