MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_bytes_with_pool

Function test_bytes_with_pool

arrow-buffer/src/bytes.rs:273–301  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 2

defaultFunction · 0.85
claimMethod · 0.45

Tested by

no test coverage detected