Adds support for memory management
Project description
memorymanagement
Provides memory management support.
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. This 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 memorymanager package from PyPI as follows:
pip install memorymanagement
You can also install the memorymanager package (Test PyPI versión of memorymanager) from TestPyPI as follows:
pip install --index-url https://test.pypi.org/simple/ memorymanager
For TestPyPI versión, --no-deps option is not needed because it has no dependencies.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memorymanagement-1.0.0.tar.gz.
File metadata
- Download URL: memorymanagement-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4986a35dbf24cce3b3df23bb07cc75a19d6abf4299f862af4d3654c552bc3bf8
|
|
| MD5 |
deb62bca2e871b84a9102bc89f24161b
|
|
| BLAKE2b-256 |
c88f6adc921c83d415deeac83f8c142685a6a7fdbf69cf62ba3f8cf2792a73de
|
File details
Details for the file memorymanagement-1.0.0-py3-none-any.whl.
File metadata
- Download URL: memorymanagement-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9261f7d06f37d617b94667b58fa336a6dfef0e856465a188edc2a2d7708eb3b4
|
|
| MD5 |
ebf88de7c88a7d45dbc8c515467bce30
|
|
| BLAKE2b-256 |
1f3bc02d79a8bda365cc087df6924528e67bcadf54c142aef4d3ab758f63b4cc
|