Overview
Memory management is provided through:sys/memory.h- Low-level memory allocation syscallslv2/memory.h- Memory mapping functionssys/heap.h- Heap management utilities
Memory Types
Direct Memory Allocation
Basic Allocation
Size of memory to allocate in bytes
Memory allocation flags (page size and access rights)
Pointer to receive the allocated memory address
Returns 0 on success, non-zero error code on failure
Page Size Flags
Page Size Options
Page Size Options
| Constant | Description |
|---|---|
SYS_MEMORY_PAGE_SIZE_1M | Use 1MB pages (0x400) |
SYS_MEMORY_PAGE_SIZE_64K | Use 64KB pages (0x200) |
Larger page sizes can improve performance but may waste memory if allocating small amounts.
Access Rights Flags
Access Rights Flags
| Constant | Description |
|---|---|
SYS_MEMORY_ACCESS_RIGHT_PPU_THR | PPU thread access (0x08) |
SYS_MEMORY_ACCESS_RIGHT_HANDLER | Handler access (0x04) |
SYS_MEMORY_ACCESS_RIGHT_SPU_THR | SPU thread access (0x02) |
SYS_MEMORY_ACCESS_RIGHT_RAW_SPU | Raw SPU access (0x01) |
SYS_MEMORY_ACCESS_RIGHT_ANY | All access rights (0x0F) |
SYS_MEMORY_ACCESS_RIGHT_NONE | No access (0xF0) |
Protection Flags
Protection Flags
| Constant | Description |
|---|---|
SYS_MEMORY_PROT_READ_ONLY | Read-only access (0x80000) |
SYS_MEMORY_PROT_READ_WRITE | Read-write access (0x40000) |
Freeing Memory
Memory Containers
Memory containers provide isolated memory pools for resource management.Memory Mapper
The memory mapper provides advanced memory management with virtual address mapping.Address Allocation
Memory Allocation and Mapping
Search and Map
Heap Management
PSL1GHT provides a custom heap implementation for fine-grained memory control.Heap Structure
Heap Initialization
Heap Allocation
Alignment Requirements
Many PS3 operations require specific memory alignment.Complete Memory Example
Memory Usage Tips
Choose Page Size Wisely
Use 1MB pages for large allocations, 64KB for smaller ones to reduce waste.
Always Free Memory
Prevent memory leaks by freeing all allocated memory when done.
Respect Alignment
Ensure proper alignment for SPU and DMA operations.
Use Containers
Isolate memory pools with containers for better resource management.
Memory Limits:The PS3 has limited RAM available to applications (typically around 256MB for games). Always be mindful of memory usage and implement proper cleanup.
Best Practices
- Check all allocations - Always verify memory allocation succeeded before use
- Use appropriate page sizes - Match page size to allocation size
- Align for hardware - Use required alignment for SPU and DMA
- Free in reverse order - Generally free memory in reverse of allocation order
- Container isolation - Use containers to limit resource usage
- Avoid fragmentation - Consider using custom heaps for many small allocations
See Also
- Threads - Thread-safe memory access
- Processes - Process memory configuration
- Filesystem - I/O buffer management