| 271 | |
| 272 | #[test] |
| 273 | fn test_bytes_with_pool() { |
| 274 | // Create a standard allocation |
| 275 | let buffer = unsafe { |
| 276 | let layout = |
| 277 | std::alloc::Layout::from_size_align(1024, crate::alloc::ALIGNMENT).unwrap(); |
| 278 | let ptr = std::alloc::alloc(layout); |
| 279 | assert!(!ptr.is_null()); |
| 280 | |
| 281 | Bytes::new( |
| 282 | NonNull::new(ptr).unwrap(), |
| 283 | 1024, |
| 284 | Deallocation::Standard(layout), |
| 285 | ) |
| 286 | }; |
| 287 | |
| 288 | // Create a memory pool |
| 289 | let pool = TrackingMemoryPool::default(); |
| 290 | assert_eq!(pool.used(), 0); |
| 291 | |
| 292 | // Reserve memory and assign to buffer. Claim twice. |
| 293 | buffer.claim(&pool); |
| 294 | assert_eq!(pool.used(), 1024); |
| 295 | buffer.claim(&pool); |
| 296 | assert_eq!(pool.used(), 1024); |
| 297 | |
| 298 | // Memory should be released when buffer is dropped |
| 299 | drop(buffer); |
| 300 | assert_eq!(pool.used(), 0); |
| 301 | } |
| 302 | |
| 303 | #[test] |
| 304 | fn test_bytes_drop_releases_pool() { |