lowlevel
A low-level memory management library for Python, implemented in C
and integrated through ctypes.
lowlevel provides operations for allocating, freeing, identifying,
writing, and reading raw memory blocks.
Version
v1.0.0
Features
- Dynamic memory allocation
- Memory deallocation
- Allocation identification through numeric IDs
- Writing raw bytes to memory
- Reading raw bytes from memory
- Internal allocation management
- Python/C integration through
ctypes - DLL compilation
- Binary data handling
Architecture
Python
│
│ ctypes
▼
memory.dll
│
▼
C code
│
├── malloc()
├── free()
├── memcpy()
├── Allocation
└── Queue
Each allocated memory block receives a numeric ID that can be used to locate the allocation.
Python API
allocate(size)
Allocates size bytes of memory and returns its address.
address = allocate(1024)
free(address)
Frees the memory associated with an address.
free(address)
get_id(address)
Returns the ID associated with an allocation.
allocation_id = get_id(address)
write(id, size, data)
Writes raw bytes data to the memory associated with an ID.
data = b"Hello World!"
write(id, len(data), data)
read(id, size)
Reads size bytes from an allocation and returns them as Python
bytes.
data = read(id, len(data))
print(data)
Example
data = b"Hello World!"
address = allocate(len(data))
try:
allocation_id = get_id(address)
write(allocation_id, len(data), data)
result = read(allocation_id, len(data))
print(result)
finally:
free(address)
Output:
b'Hello World!'
Numeric Data
Because lowlevel works with raw memory, numeric values can be
converted to bytes before being stored.
value = 123456
data = value.to_bytes(4, byteorder="little", signed=True)
address = allocate(4)
try:
allocation_id = get_id(address)
write(allocation_id, 4, data)
result = read(allocation_id, 4)
value = int.from_bytes(result, byteorder="little", signed=True)
print(value)
finally:
free(address)
Audio Test
lowlevel was also tested with audio data. An audio file was loaded as
bytes, stored in C-managed memory, read back through the library, and
successfully reproduced with pygame.
Audio file → bytes → allocate() → write() → C memory
│
▼
read() → bytes → pygame → Audio
This demonstrates that the library can handle arbitrary binary data without the C layer needing to interpret its semantic type.
Internal Structure
Each allocation is represented by an Allocation node:
typedef struct Allocation
{
int id;
void *memory;
size_t size;
void *copy;
struct Allocation *next;
} Allocation;
Allocations are managed through a queue:
typedef struct Queue
{
Allocation *first;
Allocation *last;
} Queue;
Compilation
Using GCC/MinGW-w64:
gcc -shared -Wall -Wextra -o memory.dll memory.c
The generated memory.dll must be available to the Python application.
Technologies
- C
- Python
ctypes- GCC / MinGW-w64
- DLL
- pygame
Status
v1.0.0 --- Completed
- Memory allocation
- Memory deallocation
- Allocation IDs
- Byte writing
- Byte reading
- Python/C integration
- Functional DLL
- Numeric data testing
- Audio data testing
- Successful audio playback
Project Objective
lowlevel was developed as a practical project for studying low-level
programming, memory management, pointers, data structures, C, and
Python/C integration.
It also provides a foundation for future applications that require direct manipulation of binary data in memory.
lowlevel v1.0.0
Developed by Natanael Rodrigues.
Release files for lowlevel 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lowlevel-1.0.0.tar.gz | 15.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lowlevel-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.1 kB
Release files / lowlevel-1.0.0.tar.gz
| Download URL | lowlevel-1.0.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15e91d44fdadb03efb035a2868aeeb5ee304754e8717b50c7ad41dcab9ed4058
|
|
BLAKE2b-256 checksum How to use checksums |
05de6451e8aa0e8bdcae38a455b2979016c430b1410cc2815010e5bb1c98190d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / lowlevel-1.0.0-py3-none-any.whl
| Download URL | lowlevel-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc0019efabea66931964756ecd6bc74d41275b61292be6fd201bd8f67de6e839
|
|
BLAKE2b-256 checksum How to use checksums |
1b8bbaa42d09bc6c6b272e0c5b9e66fcb5f99327af2def3a9514628516fe01f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|