MCPcopy Create free account
hub / github.com/That3Percent/second-stack / acquire

Method acquire

src/lib.rs:155–179  ·  view source on GitHub ↗

Slice from the top pool, sizing up if necessary.

(&mut self, count: usize)

Source from the content-addressed store, hash-verified

153 }
154 /// Slice from the top pool, sizing up if necessary.
155 pub fn acquire<T>(&mut self, count: usize) -> StackAlloc<T> {
156 let pools = &mut self.pools;
157 let mut prev_used = 0;
158 let mut next_pool = 0;
159 if let Some(top) = self.top {
160 let pool = &pools[top];
161 if pool.usable_size::<T>() > count {
162 return self.get_slice(count, top);
163 }
164 prev_used = pool.bytes_used();
165 next_pool = top + 1;
166 }
167 // The choices are to specify an alignment, or to make sure that the allocation
168 // is large enough to accommodate alignment padding. Choosing the latter.
169 let min_bytes = prev_used + size_of::<T>() * count + align_of::<T>();
170 for i in next_pool..NUM_POOLS {
171 let size = size_for_i(i);
172 if size_for_i(i) >= min_bytes {
173 pools[i] = PoolAlloc::new(size);
174 self.top = Some(i);
175 return self.get_slice(count, i);
176 }
177 }
178 panic!("Allocation size too large");
179 }
180
181 /// Release a previously acquired pointer.
182 pub fn release<T>(&mut self, ptr: &StackAlloc<T>) {

Callers 2

acquire_uninitializedFunction · 0.80
acquireFunction · 0.80

Calls 3

size_for_iFunction · 0.85
get_sliceMethod · 0.80
bytes_usedMethod · 0.80

Tested by

no test coverage detected