From 0f04f0867a641f8447960faee9058a8dc64216b2 Mon Sep 17 00:00:00 2001 From: Adam Cimarosti Date: Fri, 27 Sep 2024 16:54:54 +0100 Subject: [PATCH] allocator --- src/vec.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vec.rs b/src/vec.rs index 591c80b..e3f15e9 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -17,6 +17,10 @@ impl Vec { } } + pub fn allocator(&self) -> &A { + self.inner.allocator() + } + #[inline] pub fn capacity(&self) -> usize { self.inner.capacity() @@ -273,7 +277,7 @@ mod tests { #[test] fn test_basics() { let wma = WatermarkAllocator::new(32); - let mut vec = Vec::new_in(wma); + let mut vec = Vec::new_in(wma.clone()); assert_eq!(vec.len(), 0); assert_eq!(vec.capacity(), 0); assert!(vec.is_empty()); @@ -285,6 +289,14 @@ mod tests { vec.push(4).unwrap(); assert_eq!(vec.len(), 4); assert_eq!(vec.capacity(), 4); + assert_eq!( + wma.in_use.load(Ordering::SeqCst), + vec.capacity() * size_of::() + ); + assert_eq!( + vec.allocator().in_use.load(Ordering::SeqCst), + vec.capacity() * size_of::() + ); let _err: TryReserveError = vec.push(5).unwrap_err(); assert_eq!(vec.as_slice(), &[1, 2, 3, 4]); assert_eq!(vec.len(), 4);