UnsafeCollections is a learning-oriented library that provides unsafe data structures to help understand how memory management works under the hood.
The project is intentionally unsafe. Its goal is education, not production use.
This library uses unsafe memory operations.
- ❌ Not production-ready
- ❌ No safety guarantees
- ❌ Easy to crash or leak memory
Use only for learning, experiments, and exploration.
- Understand manual memory management
- Learn how pointers and raw memory behave
- See what Swift normally protects you from
- Explore performance and layout trade-offs
- UnsafeQueue
- UnsafeStack
- UnsafeList (Doubly Circular Linked List)
- UnsafeTree (Binary Search Tree)
Each data structure:
- Uses raw pointers
- Manages memory manually
- Avoids Swift safety abstractions on purpose
- Allocation and deallocation
- Ownership and lifetime issues
- Dangling pointers
- Double free / memory leaks
- Why ARC and safety checks exist
🛠 Installation
-
Open your project in Xcode.
-
Go to File → Add Packages… and paste this URL:
https://github.com/BarreiroFontelaMax/UnsafeCollections.git
Click Next.
-
Pick Branch: main or a specific version tag, then click Next again.
-
Choose the target(s) to attach the package to and click Add Package.
-
Check Project Navigator → Swift Packages → Package Dependencies to confirm it’s there.
Now you can import it in your code
You can import the whole package:
import UnsafeCollectionsOr import individual modules if you only need specific data structures:
import UnsafeQueue
import UnsafeStack
import UnsafeList
import UnsafeTreeimport UnsafeQueue
let queue = UnsafeQueue<Int>()
queue.enqueue(1)
queue.enqueue(2)
let value = queue.dequeue()The project uses Swift Testing.
Each test:
- Initializes its own data structures
- Avoids shared state
- Focuses on memory correctness
- Students learning systems programming
- Developers curious about memory internals
- People who want to understand what "unsafe" really means
MIT License
See LICENSE.txt for details.
Contributions are welcome for educational purposes.
Please:
- Keep code unsafe by design
- Add comments explaining memory behavior
- Avoid hiding problems behind safety wrappers